I have a linearLayout having some autocomplete and textboxes. I want to insert a shape (rectangle) in linearlayout. How can i achieve this. I am new comer to android.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="@+id/layout">
<AutoCompleteTextView android:id="@+id/autocompleteCountry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/CONTRY_LABEL"
/>
<AutoCompleteTextView android:id="@+id/locationAutoCompleteFrom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/from"
android:visibility="gone"
/>
<AutoCompleteTextView android:id="@+id/locationAutoCompleteTO"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/to"
android:visibility="gone"
/>
<!-- <Button android:id="@+id/buttonRoute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/buttonRouteText"
android:enabled="false"
android:clickable="true"
/>
-->
I May recommand to create custom view by implementing Linearlayout class and override ondraw() mtd to draw any shape u want.Hope this may help in to go in right direction
You can do something like below
if you want to add rectangle simply add nested layout(say linearlayout) within your layout and set
android:background="yourcolor"
//you can add color using hash color valuesyou change all the relative properties as you want say size,margins,etc
You should use a ShapeDrawable for the background of the component you want to add the style to.
A shape drawable is created in XML, with the following syntax (this one shows a rectangle, with the rounded corners, but there is lots you can do to customize this to look however you want). This file (named background_square.xml or whatever) should be put in your drawable folder:
Then, when you want to add it to a View, you can use the following syntax in your XML: