Aut*_*pps 0 android android-launcher android-actionbar-compat
我的启动器图标没有出现在我的ActionBar中,尽管设置了android:icon属性(当我安装应用程序时,启动器出现在我的主屏幕上).注意:我正在使用片段,他们也提供了操作项 - 但这不应该影响主页图标集,对吗?
以下是我的清单中的一些相关代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns="http://schemas.android.com/apk/res/android"
package="com.mywebsite.myapp">
<application
android:name=".MyApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
...etc...
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
来自styles.xml的代码:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
来自menu_main.xml的代码,以获得良好的衡量标准:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<!-- Note: my fragments also contribute action items. -->
<item
android:id="@+id/action_about"
android:orderInCategory="100"
android:title="@string/menu_item_about"
app:showAsAction="never" />
</menu>
Run Code Online (Sandbox Code Playgroud)
以及MainActivity.java中的一些代码:
package com.mywebsite.myapp;
import android.support.v7.app.ActionBarActivity;
...etc...
public class MainActivity extends ActionBarActivity {
...lots of code; let me know if you need anything...
// possibly relevant
@Override public boolean onCreateOptionsMenu(Menu menu) {
getMeunInflater().inflate(R.menu.menu_main, menu);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:此问题与主持人链接的问题不重复.这个问题的答案并没有解决我的问题; 但是,我在下面标记为正确的答案.具体来说,呼叫setLogo(int)不是我问题的解决方案.actionBar.setDisplayShowHomeEnabled(true);但是,打电话确实解决了我的问题.看到?不同的问题.
确保显示它:
actionBar.setDisplayShowHomeEnabled(true);
Run Code Online (Sandbox Code Playgroud)
然后,请注意,setIcon()和setLogo(),如果您已设置只会工作displayOptions相应.你可以使用:
actionBar.setDisplayOptions(ActionBar.DISPLAY_USE_LOGO);
Run Code Online (Sandbox Code Playgroud)
所以你的ActionBar意志就是你AndroidManifest.xml的标志.要么:
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setIcon(R.drawable.ic_launcher);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3035 次 |
| 最近记录: |