[英]ActionBar Not Showing Icons, Android Studio
I recently moved from eclipse to android studio. 我最近从eclipse转到了android studio。 while importing my project to android studio, i faced a problem with action bar icons not being displayed when running on my galaxy s3.
将项目导入android studio时,我在银河s3上运行时遇到操作栏图标无法显示的问题。
this is the xml code 这是xml代码
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".StartingNowHere">
<item
android:id="@+id/menu_item_share"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_action_share"
android:title="@string/Share"/>
<item
android:id="@+id/ShopCart"
android:icon="@drawable/shopping"
app:showAsAction="ifRoom"
android:title="@string/MyCart"/>
<item
android:id="@+id/GoHome"
android:icon="@drawable/ic_home1"
app:showAsAction="ifRoom"
android:title="@string/nowhome"/>
</menu>
when using the preview option in the android studio, i can see those 3 item displayed on the virtual preview device. 在android studio中使用预览选项时,我可以看到虚拟预览设备上显示的那3个项目。
this is the java part of the code, in this code i made a Toast to see if it gets processed and it did . 这是代码的Java部分,在这段代码中,我做了一个Toast,看它是否得到处理,是否做到了。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
Toast.makeText(getApplicationContext(),"test",Toast.LENGTH_LONG).show();
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// if nav drawer is opened, hide the action items
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
//menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
note: this code as it is works fine on eclipse, when i imported the project into android studio, the action bar icons stopped showing . 注意:这段代码在eclipse上工作正常,当我将项目导入android studio时,动作栏图标停止显示。
I also have this problem. 我也有这个问题。 I just ignore Android Studio's red line and keep it as android:showAsAction="ifRoom".
我只是忽略了Android Studio的红线,并将其保留为android:showAsAction =“ ifRoom”。 It works for me.
这个对我有用。
Try replace this: 尝试替换此:
app:showAsAction="ifRoom"
with: 有:
android:showAsAction="ifRoom"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.