Sto cercando di creare un tema appcompat ma il colore non funziona e l'icona non mostrerà ... forse mi manca qualcosa. Ecco il mio xml:Supporto ActionBar non visualizza il colore corretto con API 21
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<color name="background_test">#410000</color>
<color name="font_general">#ffffff</color>
<style name="MyTheme"
parent="@style/Theme.AppCompat">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="AudioFileInfoOverlayText">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingBottom">2dp</item>
<item name="android:textColor">#ffffffff</item>
<item name="android:textSize">18sp</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">1</item>
</style>
<!-- general styles for the action bar -->
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:icon">@drawable/ic_launcher</item>
<item name="icon">@drawable/ic_launcher</item>
<item name="background">@color/background_test</item>
<item name="android:background">@color/background_test</item>
</style>
</resources>
Cosa devo aggiungere per farlo funzionare?
EDIT:
Non funzionerà con una barra degli strumenti o ... dopo essere stata impostata:
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
perderà tutto il tema definito dall'utente e si ottiene solo il tema genitore .. . Qui sono i miei XMLs (Sì ho un sacco di valori ridondante/test come ho voluto provare tutto)
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
background="?attr/colorPrimary"
app:popupTheme="@style/MyActionBarStyle"
android:background="?attr/colorPrimary"
app:theme="@style/MyActionBarStyle"
/>
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<!-- the theme applied to the application or activity -->
<color name="background_test">#410000</color>
<color name="font_general">#ffffff</color>
<!-- general styles for the action bar -->
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="actionBarStyle">@style/MyActionBarStyle</item>
<item name="android:panelColorBackground">@color/background_test</item>
<item name="android:headerBackground">@color/background_test</item>
<item name="android:colorBackground">@color/background_test</item>
<item name="android:backgroundSplit">@color/background_test</item>
<item name="backgroundSplit">@color/background_test</item>
<item name="colorAccent">@color/background_test</item>
<!-- Here we setting appcompat’s actionBarStyle -->
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">@color/background_test</item>
<item name="colorPrimaryDark">@color/background_test</item>
</style>
<style name="MyActionBarStyle">
<item name="colorAccent">@color/background_test</item>
<!-- Here we setting appcompat’s actionBarStyle -->
<item name="android:panelColorBackground">@color/background_test</item>
<item name="android:headerBackground">@color/background_test</item>
<item name="android:colorBackground">@color/background_test</item>
<item name="android:backgroundSplit">@color/background_test</item>
<item name="backgroundSplit">@color/background_test</item>
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">@color/background_test</item>
<item name="colorPrimaryDark">@color/background_test</item>
<item name="android:background">@color/background_test</item>
<item name="background">@color/background_test</item>
</style>
<style name="AudioFileInfoOverlayText">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingBottom">2dp</item>
<item name="android:textColor">#ffffffff</item>
<item name="android:textSize">18sp</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">1</item>
</style>
</resources>
Screenshot:
http://i.imgur.com/4iohVwP.png
Nuovo EDIT: Non funzionerà dal codice o ...
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
ActionBar test=getSupportActionBar();
test.setLogo(R.drawable.ic_launcher); //this is the only one working...
test.setBackgroundDrawable(new ColorDrawable(0x410000));
test.setDisplayShowTitleEnabled(false);
test.setDisplayShowTitleEnabled(true);
EDIT:
Ci sono alcuni bug segnalati per il nuovo AppCompat-v7, questo è probabilmente un bug:
http://code.google.com/p/android/issues/detail?id=77763&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
Non funzionerà mai con la barra di azione predefinita, il colore è sempre lo stesso ma il suggerimento di Toolbar è il migliore quindi non perderò tempo con ActionBar regolare – Arnold
Non funzionerà neanche ... Quando installo la barra degli strumenti come supportactionbar perderà è colore!. Ho modificato la domanda. – Arnold
Se ho impostato lo "sfondo" sul tema, cambierà il colore, ma imporrà anche tutto il resto con lo stesso colore, quindi anche le immagini trasparenti avranno un aspetto negativo – Arnold