Action bar app icon missing with Android 5

前端 未结 4 942
面向向阳花
面向向阳花 2021-02-14 08:59

Just rebuilt my app using the Android 5 SDK and associated appcompat.

Seems to work fine but my app icon is no longer showing in top left hand corner. The icon to open

相关标签:
4条回答
  • 2021-02-14 09:06

    You shouldn't have an icon in an API OS 5+ app. By default it is not displayed (and this is the preferred behavior). The Toolbar docs specifically state this:

    "In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer."

    http://developer.android.com/reference/android/widget/Toolbar.html

    0 讨论(0)
  • 2021-02-14 09:12

    I too noticed that the default projects created by Android Studio were missing the icon in the action bar. Here's how I fixed it.

    Disclaimer: This solution will result in in the Material theme being dropped in favor of the older JellyBean/Kitkat styles.

    First, change themes setting in styles.xml from this:

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    

    To this:

    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    

    Now change all your Activities to inherit from android.app.Activity instead of android.support.v7.app.ActionBarActivity. That is:

    Change this:

    import android.support.v7.app.ActionBarActivity;
    
    public class MainActivity extends ActivityBarActivity {
    

    To this:

    import android.app.Activity;
    
    public class MainActivity extends Activity {
    

    The end of result of doing this is an app that has the Holo theme more commonly seen on Jelly Bean and Kitkat.

    0 讨论(0)
  • 2021-02-14 09:21

    Use the code below in onCreate:

    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setLogo(R.drawable.ic_launcher);
    getSupportActionBar().setDisplayUseLogoEnabled(true);
    
    0 讨论(0)
  • 2021-02-14 09:22

    Make sure to extend ActionBarActivity rather than Activity. And add the following code:

    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setLogo(R.drawable.ic_launcher);
    getSupportActionBar().setDisplayUseLogoEnabled(true);
    
    0 讨论(0)
提交回复
热议问题