I am new to android, currently. I have created simple EditTexts and search bar type EditText .. But now I am stuck at creating attached EditTexts like in the following snapshot.
for 1st edit text:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<corners android:topLeftRadius="4dp"
android:topRightRadius="4dp" />
<solid android:color="#fff" />
<stroke
android:width="1dp"
android:color="#777" />
</shape>
second:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#fff" />
<stroke
android:width="1dp"
android:color="#777" />
</shape>
third:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<corners android:bottomLeftRadius="4dp"
android:bottomRightRadius="4dp" />
<solid android:color="#fff" />
<stroke
android:width="1dp"
android:color="#777" />
</shape>
You could use parent LinearLayout view and make it roundtable using shapes (like the other answer). Then just put any number of EditText views and use separator view between them.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#000000"/>
<corners android:radius="3dp" />
</shape>
using the following xml code to create a new drawable and set it as background to your LinearLayout that contains EditViews.
Related
I have EditText. How can I set its border width and colour only and in xml? I can't figure it out and all I've found so far didn't explain that in a simple way. But I believe that so such a simple thing there must be a simple way to do it.
Create a drawable xml for your EditText with named EditTextStyle.xml in your Drawable Folder like below
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="2dp"
android:color="#000000" />
</shape>
Change your color and width according to your requirement and add this as the background of your EditText of your Layout xml
android:background="#drawable/EditTextStyle"
You can create Customize editText xml in Drawable folder like
custom_edttext.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#00000000" />
<stroke
android:width="1dp"
android:color="#641E1E" />
<corners
android:topLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
/>
</shape>
and use custom_edittext.xml as background of editText
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/custom_edittext"/>
I don't have enough karma to say this as a comment. So typing as answer. See this link. Just create an xml file in drawable(here rounded_edittext.xml in the example) and set background for the EditText as
android:background="#drawable/rounded_edittext"
The <stroke> in the rounded_edittext.xml is used to set the thickness and color of the border of the EditText.
Here's the rounded_edittext.xml as shown in the link.
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#2f6699" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp" android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp" />
</shape>
I hope this answer match with your needs.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#76b385" />
<corners android:radius="12dp" />
</shape>
</item>
<item
android:bottom="5dp"
android:left="1dp"
android:right="1dp">
<shape android:shape="rectangle" >
<gradient
android:angle="-90"
android:centerColor="#ffffff"
android:centerX="50%"
android:endColor="#ffffff"
android:startColor="#ededed"
android:type="linear" />
<corners android:radius="5dp" />
</shape>
</item>
</layer-list>
Modify this xml with your needs.
put this file in your drawable folder
edit_text_back.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#00000000" />
<stroke
android:width="1dp"
android:color="#641E1E" />
<corners
android:radius="5dp" />
</shape>
and add use this drawable as background to your edittext as
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/edit_text_back"/>
If you need any assistance.Please let me know and mark this answer up.if it helps.Happy coding :)
How we can do this like the below image on EditText and Button in material design on Android ?
Cheers!
Create a xml with the below code in drawable and set it as your edittext bg..
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#00FFFFFF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<stroke android:width="1dp" android:color="#FFFFFFFF" />
</shape>
You may find what you want here:
http://developer.android.com/guide/topics/ui/controls/button.html#Style
Use this xml for the EditText, remove transparent and add color for Button:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#android:color/transparent"
android:endColor="#android:color/transparent"
android:angle="270" />
<corners android:radius="30dp" />
<stroke android:width="5px" android:color="#android:color/white" />
</shape>
I have used
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#ffffff" />
</shape>
and in my Edittext I set this set as background
android:background="#drawable/rounded_edittext"
I only want to set border color only in order to achieve this, i try to use color in corners but it doesn't allow to compile.
<corners
android:Color="#00ff00"
android:radius="0dp" />
try this
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<stroke
android:width="2dp"
android:color="#00ff00" />
</shape>
I'm using the following code to display a separator view in my activity:
<View
android:id="#+id/view"
android:layout_width="2dp"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_toLeftOf="#id/signoutbutton"
android:background="#drawable/separator" />
My separator.xml file is as follows:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<stroke
android:height="54dp"
android:width="1dp"
android:color="#FFFFFF" />
<solid android:color="#FFFFFF" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<stroke
android:height="54dp"
android:width="1dp"
android:color="#color/blue" />
<solid android:color="#color/blue" />
</shape>
</item>
</layer-list>
however, I am achieving this
The problem is that only the blue color is shown and not the white as I had stated in the drawable file. How can I correct this?
you should try to use as below:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<gradient
android:endColor="#FFFFFF"
android:startColor="#color/blue"
android:angle="90" />
</shape>
</item>
</layer-list>
For more info here LayerList
Hope this help you
Can anybody tell me how to create an editable textbox with rounded corners in android?
I tried with this code but it's not working:
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFF" />
<corners android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp" android:topLeftRadius="15dp"
android:topRightRadius="15dp" />
</shape>
Thanks
Hey have a look about the problem in this discussion : How to create EditText with rounded corners? ..I am sure it will surely gonna help you.
Just create an xml file in your drawable folder name as round_corner.xml.And add this following code.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners
android:bottomLeftRadius="3dp"
android:bottomRightRadius="3dp"
android:radius="3dp"
/>
<solid
android:color="#android:color/white"/>
</shape>
At Last you add this xml in background property of your Edittext as follows:-
<EditText
android:id="#+id/ed1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round_corner"
/>
Done..Definitely it works..
Use This Code
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="schemas.android.com/apk/res/android"; android:shape="rectangle" android:padding="10dp"> <solid android:color="#FFFFFF" >
<corners android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp" android:topLeftRadius="15dp" android:topRightRadius="15dp" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#ECE9E6"
android:endColor="#FFFFFF"
android:angle="270"
/>
<corners
android:radius="15dp" />
<stroke
android:width="1dip"
android:color="#ffffff"
/>
<padding
android:left="4dp"
android:top="4dp"
android:right="4dp"
android:bottom="4dp"
/>
</shape>