一切正常,我必须改变一些东西:/似乎无法找到现在的东西。
我的活动操作栏现在看起来有点“缩小”,并且没有选项菜单图标:
logcat上似乎没有任何东西。
MainActivity :
@覆盖 public boolean onCreateOptionsMenu(Menu menu){ //给菜单充气;这会将项目添加到操作栏(如果存在)。 getMenuInflater()。inflate(R.menu.menu_main,menu); 返回true; }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
SettingsDialogFragment settingsdf = new SettingsDialogFragment();
settingsdf.show(getFragmentManager(),"SettingsDialogFragment");
return true;
}
else if (id == R.id.action_remove_all) {
AlertDialog.Builder areYouSure = new AlertDialog.Builder(getApplicationContext());
areYouSure.setMessage("Are you sure?").setPositiveButton("Yes",areYouSureClickListener)
.setNegativeButton("Oh no!",areYouSureClickListener).show();
return true;
}
else if (id == R.id.action_about) {
AboutDialogFragment adf = new AboutDialogFragment();
adf.show(getFragmentManager(),"AboutDialogFragment");
return true;
}
return super.onOptionsItemSelected(item);
}
RES /菜单/ menu_main.xml :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" android:showAsAction="never" />
<item android:id="@+id/action_remove_all" android:title="@string/action_remove_all"
android:orderInCategory="100" android:showAsAction="never" />
<item android:id="@+id/action_about" android:title="@string/action_about"
android:orderInCategory="100" android:showAsAction="never" />
</menu>
我还尝试将android:showAsAction
更改为always
。
的AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.doar.ori.doar" >
<uses-permission android:name="android.permission.INTERNET" />
<application
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" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.ADD"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.STATUS_UPDATE"/>
</intent-filter>
</activity>
<service
android:name="StatusUpdateService"
android:icon="@drawable/ic_launcher"
android:label="@string/service_name"
>
</service>
</application>
</manifest>
RES /值/ styles.xml / styles.xml :
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
修改:
所以我发现这个问题必须与主题有关。问题发生在运行Lolipop的模拟器上,这是sdk级别21,所以我改变了res/values/styles.xml\styles.xml(v21)
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Light">
</style>
</resources>
到此:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
</style>
</resources>
现在它有效。在build.gradle上,我将所有compileSdkVersion
,minSdkVersion
和targetSdkVersion
设置为19.这是否意味着Theme.Light
在应用上无法使用?