bạn tạo Thanh tác vụ tùy chỉnh và có thể thay đổi Màu nền tiêu đề, bất kể bạn muốn gì.
Thực hiện theo các bước sau:
Chỉ có thể thực hiện điều này để làm cho Custom Sherlock bar for Title.
tạo tệp xml riêng biệt cho tiêu đề trên Ứng dụng.
rằng tập tin chứa như thế này ..
Trong bố trí tùy chỉnh này, chúng ta có thể có khả năng thay đổi màu nền sử dụng mã màu ..
header_sherlock.xml
<LinearLayout 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"
android:orientation="horizontal"
android:weightSum="3"
android:background="#008000"
>
<TextView
android:id="@+id/header_tvleft"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="left"
android:layout_marginTop="@dimen/margintop"
android:clickable="true"
android:paddingLeft="@dimen/layoutpaddingleft"
android:text="Textview"
android:textColor="#ffffff"
android:textSize="@dimen/header_leftbtn"
/>
<TextView
android:id="@+id/header_tvcenter"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:layout_marginTop="@dimen/margintop"
android:layout_marginRight="@dimen/sherlockpaddingright"
android:layout_marginLeft="@dimen/sherlockpaddingleft"
android:text="Textview"
android:textColor="#ffffff"
android:textStyle="bold"
android:textSize="@dimen/header_title"
/>
<TextView
android:id="@+id/header_tvright"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="right"
android:layout_marginTop="@dimen/margintop"
android:clickable="true"
android:paddingRight="@dimen/layoutpaddingright"
android:text="Textview"
android:textColor="#ffffff"
android:textSize="@dimen/header_rightbtn"
/>
</LinearLayout>
Đối MainActivity hoặc hoạt động nào bạn muốn thêm tiêu đề:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.header_sherlock);
header_tvleft = (TextView) findViewById(R.id.header_tvleft);
header_tvleft.setText("LeftTitleName");
header_tvcenter = (TextView) findViewById(R.id.header_tvcenter);
header_tvcenter.setText("CenterTitleName");
header_tvright = (TextView) findViewById(R.id.header_tvright);
header_tvright.setText("RightTitleName");
Thử thi s Phương pháp ..
Sử dụng http://jgilfelt.github.io/android-actionbarstylegenerator để tạo một bộ tài nguyên và xem những gì có thể có liên quan mà bạn chưa thử. – CommonsWare