Cant set Android Actionbar Background correctly

前端 未结 1 864
傲寒
傲寒 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:

    
    
    

    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:

     @style/ActionBarTheme  
    

    0 讨论(0)
提交回复
热议问题