Reputation: 2897
I want to set border of Edittext and items of listview as in the picture :
My xml code is as following :
<LinearLayout
android:background="#BDD6E0"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:background="#BDD6E0"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Search"
android:textColor="#000000"
android:background="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/search_pat_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#000000"
android:layout_weight="4">
</EditText>
</LinearLayout>
<LinearLayout
android:background="#c0c0c0"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="6" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:layout_weight="1" >
</ListView>
</LinearLayout>
</LinearLayout>
What can I do to draw border in the items of listview ?
Upvotes: 7
Views: 31874
Reputation: 9
I think if you set transcriptMode property of listview it will show the borders too.
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:transcriptMode="normal" >
</ListView>
So don't need any shape xml.
Upvotes: 0
Reputation: 6533
background of listview
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dip" android:color="@color/edt_focused" />
</shape>
and add property to listview
android:divider="@drawable/list_divider" android:dividerHeight="1px"
Upvotes: 16
Reputation: 23638
To set the border in ListView
set the property android:divider="@drawable/img_list"
and android:dividerHeight="1px"
to set the height of the divider.
Use the below code to set the border of EditText
.
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>
So your EditText will look like. You can change the colors as per your needs.
Upvotes: 3
Reputation: 6925
Set the background of your list's child element as
android:background="@drawable/shape"
and then in your res>drawable create a new shape.xml
like this
<?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="#FF000000" />
</shape>
Upvotes: 5
Reputation: 6201
Create an xml drawable such as /res/drawable/textlines.xml
and assign this as a Edittext's background property.
/res/drawable/textlines.xml
<?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:width="1dp" android:color="#FF000000" />
<solid android:color="#FFDDDDDD" />
</shape>
</item>
<item android:top="1dp" android:bottom="1dp">
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#FFDDDDDD" />
<solid android:color="#00000000" />
</shape>
</item>
</layer-list>
You use this Drawable for EditText Background or List Item root Layout.
Upvotes: 3
Reputation: 17401
set following shape as the background of you list row item:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#000" />
</shape>
Upvotes: 1