【问题标题】:Why can't I see default icon in the action bar? [duplicate]为什么我在操作栏中看不到默认图标? [复制]
【发布时间】:2017-07-31 04:22:43
【问题描述】:

我以为我可以在操作栏上显示图标,但正如您所见,它不起作用,问题出在哪里? 也许它取决于compiledSdkVersion。

我的清单是默认清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.fulvio.bitsandpizzas">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我的 build.gradle:

[![android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.fulvio.bitsandpizzas"
        minSdkVersion 17
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: \['*.jar'\])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    testCompile 'junit:junit:4.12'
}

【问题讨论】:

    标签: android android-manifest android-launcher


    【解决方案1】:

    在最新版本的 Android 中,Toolbar(新的ActionBar)默认不显示该图标,如果您手动放置它,它将不符合材料设计指南:

    https://material.io

    如果你还是想把它放进去,你可以用你的AppBar 和自定义的Toolbar 创建一个toolbar.xml,并在包括你的工具栏布局在内的活动中使用它:

    <include layout="@layout/your_layout">
    

    【讨论】:

    • 我使用 Theme.AppCompat.Light 作为样式,使用 AppCompatActivity 作为活动
    【解决方案2】:

    将此代码添加到ActivityonCreate 方法中。

    getActionBar().setHomeButtonEnabled(true);
    

    或者如果你使用 SupportActionBar,那么,

    getSupportActionBar().setHomeButtonEnabled(true);
    

    【讨论】:

      【解决方案3】:

      简单的方法去MainActivity.java并粘贴这段代码

       @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          getSupportActionBar().setDisplayShowHomeEnabled(true);
          getSupportActionBar().setLogo(R.drawable.ic_launcher);
          getSupportActionBar().setDisplayUseLogoEnabled(true);        
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-06
        • 1970-01-01
        • 2013-11-04
        • 2014-10-05
        • 2012-12-02
        • 2021-02-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多