How can I add close button in title bar of the activity in android?
I have created custom title bar as suggested by this link:-= http://www.londatiga.net/it/how-to-create-custom-window-title-in-android/
This is my window_title.xml:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:paddingLeft="5dip"
android:paddingBottom="10dip"
android:background="#323331">
<TextView android:id="@+id/header_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Preview Song"
android:textSize="10dip"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip">
</TextView>
<ImageButton
android:id="@+id/header"
android:src="@drawable/button_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dip"
android:layout_marginTop="6dip"
android:background="@null" />
</RelativeLayout>
This is my custom_title.xml:-
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="@android:style/Theme.Dialog">
<item name="android:windowTitleSize">50dip</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
But this is my result now- ![enter image description here][1]
It means title content (preview song and close image) are too small, I want to increase height of this title bar. I have increased the height of title bar but this is not increasing the size of title bar but the conten开发者_运维百科ts overlaps the title bar and these button and preview song does not display.
Please suggest me what mistake I am doing ?
You have to create custom title bar and hide android title bar in your activity you add just...
android:theme="@android:style/Theme.Black.NoTitleBar"
and see this link::
http://www.londatiga.net/it/how-to-create-custom-window-title-in-android/ http://www.helloandroid.com/tutorials/how-create-custom-titlebar
well samir second link working fine for me. Have a look at the following windows_title.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:background="#323331">
<ImageView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/header1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right|center_vertical"
android:paddingRight="5dip">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
android:textSize="11dip" />
<Button
android:id="@+id/icon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/close"
android:layout_marginRight="10dp" />
<ProgressBar
android:id="@+id/leadProgressBar1"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_below="@+id/titleTvLeft"
android:layout_marginBottom="3dp" />
</LinearLayout>
</LinearLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
}
@Override
public boolean onSupportNavigateUp() {
finish();
return true;
}
You can inflate a new custom layout of yours.
精彩评论