Лентата за действие не приема лични стилове

Опитвам се да персонализирам лентата си с действия. Искам да поддържа 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>

приложението просто показва лентата за действие по подразбиране без икона, нито елементи или фон, който избрах


person Community    schedule 26.05.2015    source източник
comment
Работеше добре, докато не промених основната си дейност, разширявах от Fragments, но сега разширявам от ActionBarActivity, а също така промених извикванията getActionBar() на getSupportActionBar()   -  person    schedule 26.05.2015


Отговори (2)


Официалният начин за задаване на цвета на лентата за действие с 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.

person CommonsWare    schedule 26.05.2015
comment
добре, работи, но проблемът е, че лентата с действия не показва елементи! моля, какво мога да направя, за да поправя този проблем? - person ; 26.05.2015

Отидете на Персонализирана тема, добавете themes.xml в папката res-->values

използвайте този код за персонализирана лента за действие

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>
person Mano    schedule 26.05.2015