How to make a custom tite bar without changing the AppTheme to CustomTheme?

≡放荡痞女 提交于 2019-12-11 06:51:35

问题


I dont like how the CustomTheme looks and I want to keep the AppTheme.

but when I use a customized title bar with AppTheme it crashes telling me I cant combine numerous styles.

How can I do that?

Thanks!


回答1:


First crate your own custom layout for the ActionBar

tab_header.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/header_title"
    android:textSize="18dp"
    android:layout_gravity="center"
    android:singleLine="true"
    android:maxLines="1"
    android:paddingLeft="@dimen/dim_10"
    android:paddingRight="@dimen/dim_10"
    android:textAllCaps="false"
    android:textColor="@color/white"
    />
   </LinearLayout>

Then in your Activity call (With Home Button Enabled)

    getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
    getActionBar().setCustomView(R.layout.tab_header);

    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setDisplayHomeAsUpEnabled(true);

Without Home Button

    getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    getActionBar().setCustomView(R.layout.tab_header);

    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setDisplayHomeAsUpEnabled(true);


来源:https://stackoverflow.com/questions/18898749/how-to-make-a-custom-tite-bar-without-changing-the-apptheme-to-customtheme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!