当前位置: 代码迷 >> 综合 >> ActionBar 不能显示logo 的问题 ,背景颜色的修改, 以及ActionBar 的官方guide
  详细解决方案

ActionBar 不能显示logo 的问题 ,背景颜色的修改, 以及ActionBar 的官方guide

热度:63   发布时间:2023-12-16 16:26:46.0

使用如下四段话就可以解决actionBar不现实Logo的问题。
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setLogo(R.mipmap.qiu_ic_launcher);
actionBar.setDisplayUseLogoEnabled(true);

参考:
http://m.blog.csdn.net/blog/lchad/43674245


背景的修改:

For Android 2.1 and higher

When using the Support Library, your style XML file might look like this:

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">
        <item name="android:actionBarTabStyle">@style/MyActionBarTabs</item>        <!-- Support library compatibility -->
        <item name="actionBarTabStyle">@style/MyActionBarTabs</item>
    </style>    <!-- ActionBar tabs styles -->
    <style name="MyActionBarTabs"
           parent="@style/Widget.AppCompat.ActionBar.TabView">
        <!-- tab indicator -->
        <item name="android:background">@drawable/actionbar_tab_indicator</item>        <!-- Support library compatibility -->
        <item name="background">@drawable/actionbar_tab_indicator</item>
    </style>
</resources>

Then apply your theme to your entire app or individual activities:

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





0----------------------------------------------------------------------------------------------------------------------------

The ActionBar APIs were first added in Android 3.0 (API level 11) but they are also available in the Support Library for compatibility with Android 2.1 (API level 7) and above

Caution: Be certain you import the ActionBar class (and related APIs) from the appropriate package:

  • If supporting API levels lower than 11: 
    import android.support.v7.app.ActionBar
  • If supporting only API level 11 and higher: 
    import android.app.ActionBar

ActionBarActivity

extends AppCompatActivity,继承自AppCompatActivity


Caution: Be certain you import the ActionBar class (and related APIs) from the appropriate package:

  • If supporting API levels lower than 11: 
    import android.support.v7.app.ActionBar
  • If supporting only API level 11 and higher: 
    import android.app.ActionBar

Adding the Action Bar


As mentioned above, this guide focuses on how to use the ActionBar APIs in the support library. So before you can add the action bar, you must set up your project with the appcompat v7 support library by following the instructions in the Support Library Setup.

Once your project is set up with the support library, here's how to add the action bar:

  1. Create your activity by extending ActionBarActivity.
  2. Use (or extend) one of the Theme.AppCompat themes for your activity. For example:
    <activity android:theme="@style/Theme.AppCompat.Light" ... >

Now your activity includes the action bar when running on Android 2.1 (API level 7) or higher.

On API level 11 or higher

The action bar is included in all activities that use the Theme.Holo theme (or one of its descendants), which is the default theme when either the targetSdkVersion or minSdkVersion attribute is set to "11" or higher. If you don't want the action bar for an activity, set the activity theme to Theme.Holo.NoActionBar.

Removing the action bar

You can hide the action bar at runtime by calling hide(). For example:

ActionBar actionBar = getSupportActionBar();
actionBar.hide();
  相关解决方案