2017-03-10 45 views
0

我以爲我可以在操作欄上顯示圖標,但正如您所看到的,它無法正常工作,問題在哪裏? 也許它取決於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 Main Action screen

回答

1

的圖標是不是在Toolbar(新ActionBar)默認情況下顯示Android的最新版本,如果您手動添加,則不會遵循材料設計指南:

https://material.io

如果你想要把它無論如何,你可以創建一個toolbar.xml你AppBar和定製Toolbar並在活動中使用它,包括您的工具欄佈局:

<include layout="@layout/your_layout"> 
+0

我使用Theme.AppCompat.Light樣式,和AppCompatActivity作爲活動 – Donovant

0

添加該代碼到您的onCreate方法Activity

getActionBar().setHomeButtonEnabled(true); 

,或者如果您使用SupportActionBar然後,

getSupportActionBar().setHomeButtonEnabled(true); 
0

簡單的方式去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);   
} 
相關問題