操作栏不接受个人风格(Action bar doesn't accept personal

2019-10-23 04:49发布

我想我的personilize操作栏。 我希望它支持API-9和上面的问题是,行动起来吧不接受更改在styles.xml制造和项目没有显示。

这是我的styles.xml:

<resources>

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light"></style>

    <style name="AppTheme" parent="AppBaseTheme">

        <item name="android:windowBackground">@color/background_window</item>
        <item name="android:actionBarStyle">@style/ActionBarStyle</item>
    </style>

    <style name="ActionBarStyle" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <!--<item name="android:icon">@drawable/ic_launcher</item>-->
        <item name="android:background">#ff127d08</item>
    </style>

</resources>

应用程序只是显示默认的操作栏图标没有既不项目或背景下,我选用

Answer 1:

设置操作栏的颜色与官方途径appcompat-v7是通过colorPrimary上的活动主题:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Apptheme" parent="Theme.AppCompat">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
  </style>
</resources>

至于该图标,这已被问了很多,很多次, 答案 ( getSupportActionBar().setDisplayShowHomeEnabled(true);getSupportActionBar().setIcon(R.drawable.ic_launcher); )可以通过网络搜索找到了appcompat icon



Answer 2:

去自定义主题,添加的themes.xml内部资源 - >文件夹值

使用自定义动作条验证码

的themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="android:actionBarTabStyle">@style/MyActionBarTabs</item>

        <!-- Support library compatibility -->

        <item name="android:actionBarTabTextStyle">@style/MyTheme.ActionBar.TabText</item>
         <item name="android:actionBarTabBarStyle">@style/Divider</item>
    </style>

<!-- for Tab divider -->
<style name="Divider" parent="@android:style/Widget.Holo.ActionBar.TabBar">
    <item name="android:divider">@android:color/transparent</item> //or use your transparent drawable image
    <item name="android:showDividers">middle</item>
    <item name="android:dividerPadding">0dp</item>
</style>

    <!-- ActionBar styles -->
    <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@color/easy</item>
        <!-- Support library compatibility -->
        <item name="background">@color/easy</item>
    </style>

    <style name="MyActionBarTabs" parent="@style/Widget.AppCompat.ActionBar.TabView">
        <item name="android:background">@drawable/actionbar_tab_indicator</item>
    </style>

    <style name="MyTheme.ActionBar.TabText" parent="android:style/Widget.Holo.ActionBar.TabText">

        <!-- This is a Black text color when selected and a WHITE color otherwise -->
        <item name="android:textColor">@color/selector_tab_text</item>
    </style>

</resources>

清单文件调用- > CustomActionBarTheme

<application
        android:allowBackup="true"
        android:icon="@drawable/easylogo"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/CustomActionBarTheme" >


        <activity
            android:name="com.example.Start"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 </application>


文章来源: Action bar doesn't accept personal styles