I have a linear layout with two child items, an edittext fied and button. I set the background color of the linear layout to a shade of blue. On android api 8 the the edittext field has a white background which is how i want it to be, however on android api 17+ the edittext background is the same as the linear layout and thus makes the text input a little difficult to read since it is black.
When i change the edittext background to white (#ffffff) from the default value "?android:attr/editTextBackground", the height of the edittext becomes smaller and doesn't maintain its previous look. My question is how can i maintain the edittext's background as white without altering other attributes that are effected by "?android:attr/editTextBackground" throughout all api levels?
And also i failed to figure out which file the attribute "?android:attr/editTextBackground" points to so i could perhaps look there and edit. Thanks in advance.
The code:
<LinearLayout
android:id="#+id/llSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/search_layout_color"
android:orientation="horizontal"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingTop="6dp"
android:shadowColor="#77000000"
android:shadowDx="-2.4"
android:shadowDy="2.4"
android:shadowRadius="1.2" >
<EditText
android:id="#+id/etSearch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/hint_search"
android:scrollHorizontally="true"
android:singleLine="true"
android:textSize="#dimen/tv_textSize" >
<requestFocus />
</EditText>
<ImageButton
android:id="#+id/bSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/search"
android:src="#drawable/ic_action_search" />
</LinearLayout>
Related
I am using the default radio button without any customization. I would like to add padding to the left of the button icon. I have tried padding-left, but it is only changing the space between the icon and text.
I know it can easily achieve by using the drawable left and setting the button null, but it could lose the animation and default style.
My code
<com.google.android.material.radiobutton.MaterialRadioButton
android:id="#+id/rb_bank"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_payment_method"
android:buttonTint="#color/colorPrimaryDark"
android:padding="15dp"
android:text="#string/bank"
android:textColor="#color/textColorSecondary"
android:textSize="16sp" />
Current output
you can wrap the material button in a LinearLayout, set your background android:background="#drawable/bg_payment_method" to the LinearLayout and give
margin_left to the radioButton
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_payment_method" >
<com.google.android.material.radiobutton.MaterialRadioButton
android:id="#+id/rb_bank"
android:layout_marginLeft="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimaryDark"
android:text="#string/bank"
android:textColor="#color/textColorSecondary"
android:textSize="16sp" />
</LinearLayout>
I need to create a sign-in screen like this, am using Android studio.
Screen design.
How do I do this?
The lock and user icon is available here: http://www.fileconvoy.com/dfl.php?id=g36a32a9fc3a1ae3a99959004714c5d27f473d16f6
This is as far as I've created. I need to know how to give the colors as in the picture. I'm trying it, but it isn't working as expected. Also I need the background color not to merge with the EditText.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".Login"
android:id="#+id/">
<RelativeLayout
android:layout_width="500dp"
android:layout_height="300dp"
android:layout_marginTop="210dp"
android:layout_marginBottom="110dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/nameET"
android:hint="Username"
android:textColorHint="#000000"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/passwordET"
android:hint="Password"
android:textColorHint="#000000"
android:layout_below="#+id/nameET"
android:layout_alignLeft="#+id/nameET"
android:layout_alignStart="#+id/nameET"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN >"
android:id="#+id/button2"
android:layout_below="#+id/passwordET"
android:layout_alignLeft="#+id/passwordET"
android:layout_alignStart="#+id/passwordET"
android:layout_alignRight="#+id/passwordET"
android:layout_alignEnd="#+id/passwordET"
android:textColor="#android:color/white"
android:background="#android:color/holo_blue_dark"
android:ellipsize="end" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot Password"
android:id="#+id/textView3"
android:layout_below="#+id/button2"
android:layout_centerHorizontal="true"
android:textStyle="italic" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="35dp"
android:maxHeight="36dp"
android:id="#+id/imageView4"
android:src="#drawable/useri"
android:background="#ff4066ff"
android:layout_toLeftOf="#id/nameET"
android:layout_marginTop="220dp"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="35dp"
android:maxHeight="36dp"
android:id="#+id/imageView3"
android:src="#drawable/locki"
android:background="#ff4066ff"
android:layout_toLeftOf="#id/passwordET"
android:layout_marginTop="260dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="EGO >"
android:id="#+id/egoTV"
android:layout_marginBottom="60dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="15dp"
android:layout_above="#+id/nameET"
android:gravity="center"
android:textSize="40dp"/>
This layout is rather complex and if you create too many views, it might be very inefficient. Here is my take on this. For the "Ego" logo, create a single TextView and set the android:drawableRight to the arrow drawable you wanna use, also if you want some space between the "EGO" text and the arrow drawable, set the android:drawablePadding to the value you prefer. For the container of the 3 form controls, group them in a LinearLayout and create a 9-patch drawable and don't specify the stretchable area for the pointing-upwards arrow because when the drawable stretches, the arrow will stay the same which is what you want, you don't want it to stretch to look ugly, use padding to offset those views the way you want, and set the android:background to the stretchable 9-patch image you created. For the username and password fields, you could use the EditText view and also set the android:drawableLeft to the icons you have, you may also create custom background using the ShapeDrawable in XML. For the login button, it is the simplest to implement, create a button of course, but you need to create a new ShapeDrawable resource and use the radius element as a child of the shape root element to make the rounded corner like that, the arrow in the button you could use the greater sign on your keyboard or create an image using Inkscape which is free, very powerful application you should check out if you haven't yet, and also use the android:drawableRight attribute. Alright, last piece is just a TextView with the attribute android:textStyle set to italic. That is how I would do it, it is lots of work, but it is a little work, but you will end up with a layout that is a little more efficient (you could eliminate the use of ImageView if you followed my suggestion). Hope you find this helpful.
You use these attributes to create a shadow effect android:shadowDx android:shadowDy android:shadowColor android:shadowRadius. Dx and Dy are for the horizontal and vertical offset, positive values offset the shadows to right and down respectively, you could even use negative values in which case the shadows go the opposite directions. The radius attribute is for how blurred you want the shadow to be, and color is self-explanatory, but my favorite colors are #d9d9d9 and #550(or #555500) and, but use the #xxx is more memory efficient if any color components have the same value like #55 55 00, I just use #550.
The best way start from here.
Try to understand how work android UI.
In your project find res folder.
In that folder you can find main_activity.xml file or something like this
You can create your own UI in editor or using XML.
I have the following :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:gravity="left|center_vertical" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
android:gravity="left|center_vertical" />
</LinearLayout
I want to get my button's text to align left. Right now its aligned in the center. The textview's text is aligned left without any problems. Is there something else I need to add? I don't really have to close and reopen my IDE because I use maven to build. Any suggestions?
ANSWER
Figured it out : set android:paddingLeft="0dp" . Done. No need for gravity there.
Instead of wrap_content give some value. Actually its working but you can't see because your width is set as wrap_content
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Button"
android:gravity="left|center_vertical" />
When you set an object's gravity property, you're telling that object where you want its contents to be aligned. In your code, you're trying to align the text in a box that only as big as the text itself, which does nothing.
There are 2 ways to solve this problem.
A) You can set the button's width to be not wrap the content.
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Button"
android:gravity="left|center_vertical" />
B) You can set the width of the text-view to not be wrap content.
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Text"
android:gravity="left|center_vertical" />
Otherwise, what you're doing right now should have some text in a button where there is no space between the edge of the text and the outside of the button. If there is space there, make sure you're not setting padding or margins in the button or text.
It seems there is a padding between the bottom input section and bottom margin of an edittext by default. I have a linearlayout(horizon) including one edittext and one button. I just can't make them in one single line perfectly, since the padding between the bottom input section and bottom margin make the edittext lower than the button through I set the same height and alignment for them.
I also tried Relative layout but cannot solve the problem either, here is my layout
<RelativeLayout
android:id="#+id/SearchLinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginTop="10dp" >
<EditText
android:id="#+id/FilterEditText"
android:layout_width="fill_parent"
android:layout_height="38dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="#+id/SearchButton"
android:gravity="center_vertical"
android:hint="#string/search_or_add_a_place"
android:imeOptions="flagNoExtractUi"
android:inputType="text|textNoSuggestions"
android:textSize="15dp" />
<Button
android:id="#+id/SearchButton"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_alignParentRight="true"
android:background="#drawable/search_btn"
android:enabled="false"
android:gravity="center_vertical" />
</RelativeLayout>
changing the background of editText can solve my problem
i prefer relative layout and if you write android:layout_toLeft or android:layout_toRight it puts them beside correctly but even after that it doesnt, there is ALIGN_TOP or ALIGN_BOTTOM or ALIGN_BASELINE.
I had the same problem as you and turned to relative layout. Its easier to me.
I am working on Android 3.0.
I have a TextView on my layout and I want it to be faded after 8 characters like in the main menu. This Text is located in RelativeLayout.
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_name"
android:textStyle="bold"
android:textColor="#color/white"
android:maxWidth="50dp"
android:maxLength="8"
android:layout_below="#+id/item_frame"
android:layout_alignBottom="#+id/item_view"
android:layout_centerHorizontal="true"
android:fadingEdge="horizontal">
</TextView>
Does anyone has an idea how to fade the text after few characters?
I think you need to combine fadingEdge with ellipsize and singleLine, and even then it will only happen if the text is longer than the control's width.