【发布时间】:2015-05-09 05:23:53
【问题描述】:
我一直在尝试编写一个简单的应用程序来在 Android 上做笔记。 我想在主要活动的操作栏中显示一个“添加”按钮。但是,它仅显示为溢出。 我试过了
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_add"
android:icon="@drawable/ic_add"
android:title="@string/add"
android:showAsAction="always"></item>
</menu>
但我无法运行该应用程序,因为 android studio 告诉我
应将 app:showAsAction 与带有 xmlns:app="http://schemas.android.com/apk/res-auto" 的 appcompat 库一起使用
有什么想法吗?据我所知,我没有使用 appcompat
编辑: java类:
public class NoteChoice extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.notechooser);
SQLiteDatabase db = openOrCreateDatabase("Notes", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS Notes ( id INTEGER PRIMARY KEY AUTOINCREMENT, val VARCHAR )");
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.notechooser_actions, menu);
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.action_add:
onPause();
startActivity(new Intent("com.example.theorangeutan.notes.Create"));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
styles.xml 文件:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
<!-- Customize your theme here. -->
</style>
<style name="splash" parent="@android:style/Theme.Holo.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
【问题讨论】:
-
发布您的样式文件。
-
添加了它。 Apptheme 是所有活动中使用的,splash 用于启动画面。
标签: java android xml android-studio android-appcompat