【问题标题】:How to make a custom tite bar without changing the AppTheme to CustomTheme?如何在不将 App Theme 更改为 Custom Theme 的情况下制作自定义标题栏?
【发布时间】:2013-09-19 15:22:42
【问题描述】:

我不喜欢 CustomTheme 的外观,我想保留 AppTheme。

但是当我使用带有 AppTheme 的自定义标题栏时,它会崩溃,告诉我无法组合多种样式。

我该怎么做?

谢谢!

【问题讨论】:

    标签: android android-layout android-theme titlebar app-themes


    【解决方案1】:

    首先为 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>
    

    然后在您的 Activity 调用中(启用 Home 按钮)

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

    没有主页按钮

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

    【讨论】:

    • @NirPes 它不应该减慢应用程序的速度,您是否检查过 LogCats 是否存在内存泄漏问题?
    猜你喜欢
    • 2019-07-11
    • 2014-02-20
    • 1970-01-01
    • 2010-12-15
    • 2019-03-31
    • 1970-01-01
    • 2013-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多