Cant set Android Actionbar Background correctly

前端 未结 1 815
傲寒
傲寒 2021-01-15 06:20

The Problem When im setting the ActionBar Background Color the Bar looks like this:

i cant upload Images here so here is the File: Android ActionBar

相关标签:
1条回答
  • 2021-01-15 06:58
    getSupportActionBar().setBackgroundDrawable(draw);
    

    should be, in your case

    getSupportActionBar().setBackgroundDrawable(getResources.getDrawable(R.drawable.your_drawable_name);
    

    The Constructor of ColorDrawable takes the int that represent the color, not the id of the color. Use instenad

    ColorDrawable draw = new ColorDrawable(getResources().getColor(R.color.grey));

    Edit:

    about the style.xml, you need both the item with and without the android prefix:

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
       <item name="android:actionBarStyle">@style/ActionBarTheme</item>  
       <item name="actionBarStyle">@style/ActionBarTheme</item>
    </style>
    

    Lint is probably going to complain about it, because of the minSDK value. if it does you can add tools:ignore="NewApi" to the item with the android: prefix. For instance:

     <item name="android:actionBarStyle" tools:ignore="NewApi">@style/ActionBarTheme</item>  
    
    0 讨论(0)
提交回复
热议问题