How To Make Headers In Android With Text And Buttons Like In IOS
i want to create header in android with text and buttons like in iOS (Text in Cetner and Buttons on right and left side), i have tried but not useful at all,please guide me ... how
Solution 1:
Try this. Make header.xml file and put below code in it and use it in any layout file using include
.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/titlebar"
android:gravity="center">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/back_button"
android:background="@android:color/transparent"
android:layout_marginLeft="5.0dip"
android:id="@+id/imageButtonBack"
android:contentDescription="@string/ui_image_home_description"/>
<TextView
android:id="@+id/textViewTitleBar"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
style="@style/TitleBarText"
android:singleLine="false"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/home_button"
android:background="@android:color/transparent"
android:layout_marginRight="5.0dip"
android:id="@+id/imageButtonHome"
android:contentDescription="@string/ui_image_home_description"/>
</LinearLayout>
Note : Add the below style to style.xml in res/values folder.
<style name="TitleBarText">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textSize"> 17sp </item>
<item name="android:paddingLeft">12dip</item>
<item name="android:paddingRight">12dip</item>
<item name="android:textColor">@color/white</item>
<item name="android:singleLine">true</item>
<item name="android:ellipsize">end</item>
</style>
Solution 2:
This is an easier one. You can try this:
<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" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/header">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Back" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Next" />
</RelativeLayout>
</RelativeLayout>
Post a Comment for "How To Make Headers In Android With Text And Buttons Like In IOS"