[英]Error due to action bar activity
Hey guys when i add any action to action bar in android studio it just says add app combat..... When i added that it says to to change android to app and i changed that but when i run my application there is no action bar here is my xml and java code. 嗨,大家好,我在Android Studio的操作栏中添加了任何操作,它只是说添加了应用程序战斗.....当我添加时,它说将android更改为应用程序,并且我更改了它,但是当我运行我的应用程序时没有任何操作酒吧在这里是我的xml和java代码。 xml
XML文件
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:title="search"
android:icon="@drawable/ic_action_search"
android:id="@+id/search_icon"
android:text="search1"
android:showAsAction="always"
/>
java 爪哇
public boolean onCreateOptionsMenu(android.view.Menu menu) {
MenuInflater i= getMenuInflater();
i.inflate(R.menu.search_bar,menu);
return super.onCreateOptionsMenu(menu);
}
app is running successfully but with no action bar 应用程序运行成功,但没有操作栏
when i remove that function oncreateOptionMenu it still does not shows any action bar but it shows on my first activity actually this is menu of app here is code 当我删除该函数oncreateOptionMenu时,它仍然不显示任何操作栏,但实际上显示在我的第一个活动上,这是应用程序的菜单,这里是代码
public class Menu extends Activity {
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
setContentView(R.layout.menu);
}
//@Override
/*public boolean onCreateOptionsMenu(android.view.Menu menu) {
MenuInflater i= getMenuInflater();
i.inflate(R.menu.search_bar,menu);
return super.onCreateOptionsMenu(menu);
}*/
}
and here is manifest 这是明显的
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Base.Theme.AppCompat" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="@string/app_name"
android:theme="@style/Base.Theme.AppCompat.Light">
<intent-filter>
<action android:name=".Menu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Post the exact message to allow a more specific response. 发布确切的消息以允许更具体的响应。
showAsAction
should use your app namespace, ie: showAsAction
应该使用您的应用程序名称空间,即:
xmlns:app="http://schemas.android.com/apk/res-auto"
...
app:showAsAction="always"
You should also make sure you're using an AppCompat theme in your app style. 您还应该确保以自己的应用风格使用AppCompat主题。
The appcompat themes remove the native ActionBar and use the support ActionBar. appcompat主题将删除本机ActionBar并使用支持ActionBar。
You need to change 你需要改变
extends Activity
To 至
extends ActionBarActivity
You also need to change Base.Theme.AppCompat.Light
to Theme.AppCompat.Light
in your AndroidManifest. 您还需要在AndroidManifest
Base.Theme.AppCompat.Light
Theme.AppCompat.Light
更改为Theme.AppCompat.Light
。
Please see this blog post for more information: http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html 请参阅此博客文章以了解更多信息: http : //android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.