ActionBar background image

后端 未结 5 1107
旧巷少年郎
旧巷少年郎 2020-11-29 20:41

I\'ve inherited the Holo Light Theme and customized the background of the ActionBar with the following:

Content of styles.xml



        
相关标签:
5条回答
  • 2020-11-29 20:50

    Ok, thanks to Romain Guy on #android-dev IRC channel, it's a known bug on honeycomb / Android 3.0 which will be fixed on the next release. Since then, the only solution is do it from code, and it works :-)

     final ActionBar actionBar = getActionBar(); 
     BitmapDrawable background = new BitmapDrawable (BitmapFactory.decodeResource(getResources(), R.raw.actionbar_background)); 
     background.setTileModeX(android.graphics.Shader.TileMode.REPEAT); 
     actionBar.setBackgroundDrawable(background);
    
    0 讨论(0)
  • 2020-11-29 20:57
    mActionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.navbar));
    
    0 讨论(0)
  • 2020-11-29 21:02
    Drawable d=getResources().getDrawable(R.drawable.background_image_name);  
    getActionBar().setBackgroundDrawable(d);
    

    The above code sets the background image for the action bar.
    Hope it helps.

    0 讨论(0)
  • 2020-11-29 21:04

    Use getSupportActionBar() from android.support.v7 for backward compatability.

    0 讨论(0)
  • 2020-11-29 21:15

    You can easily do this thing. If you would like to change Action Bar background image then you place this code to your res/styles.xml file.

     <style name="Theme.MyAppTheme" parent="@android:style/Theme.Holo">
            <item name="android:actionBarStyle">@style/Theme.MyAppTheme.ActionBar</item>
        </style>
    
        <style name="Theme.MyAppTheme.ActionBar" parent="@android:style/Widget.Holo.ActionBar">
            <item name="android:background">@drawable/top_black_bg</item>
        </style>
    

    For this you have to select an image from "drawable" folder . Here I select an image "tp_black_bg.png"

    After that don't forget to declare this theme to your AndroidManifest.xml file

        <application
            .
            .
            .
            android:theme="@style/Theme.MyAppTheme" >.............</application>
    

    Now you can reopen any XML layout file , you can easily see the effect. In the same way you can also able to change the background color of ActionBar.

    Thanks.

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