我的Sherlock动作条将适用于三星galaxy s2 4.0.3和模拟器2.1但不适用于nexus 10 4.2.2,真的无法找出原因。
以下是我的相关代码:
在主要活动中:
ActionBar ab = getSupportActionBar();
ab.setDisplayShowTitleEnabled(false);
ab.setDisplayShowHomeEnabled(false);
...
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId()) {
// do stuff with CalendarContract
case R.id.action_settings:
Intent viewIntent = new Intent(this, SettingsActivity.class);
startActivityForResult(viewIntent, 2);
break;
case R.id.add_alarm:
loadTimer();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
...
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.mainmenu, menu);
return true;
}
清单:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="@drawable/icon_launcher"
android:label="@string/app_name"
android:theme="@style/MyTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AlarmReceiverActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<activity
android:name=".SettingsActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".PickADayActivity"
android:excludeFromRecents="true"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Dialog" >
</activity>
<receiver android:name="com.paradroid.paradroidalarm.MyBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity
android:name="com.appflood.AFPanelActivity"
android:configChanges="keyboardHidden" >
</activity>
<activity
android:name="com.appflood.AFFullScreenActivity"
android:configChanges="keyboardHidden|orientation"
android:launchMode="singleTask"
android:theme="@android:style/Theme.Translucent" >
</activity>
<activity android:name="com.appflood.notification.NotificationActivity" >
<intent-filter>
<action android:name="" />
</intent-filter>
</activity>
<activity
android:name="com.appflood.AFListActivity"
android:configChanges="keyboardHidden|orientation"
android:launchMode="singleTask"
android:theme="@android:style/Theme.Translucent" >
<intent-filter>
<action android:name="" />
</intent-filter>
</activity>
<activity
android:name="com.appflood.AFInterstitialActivity"
android:configChanges="keyboardHidden|orientation"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent" >
</activity>
<!-- gcm service and receiver -->
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
style.xml:
<?xml version="1.0" encoding="utf-8"?>
-->
<style name="AppBaseTheme" parent="android:Theme.Light"></style>
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="dialog_theme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="MyTheme" parent="@style/Theme.Sherlock.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionMenuTextColor">#FFFFFF</item>
</style>
<style name="MyActionBar" parent="@style/Theme.Sherlock.Light.DarkActionBar">
<item name="android:background">#89C2F6</item>
</style>
mainmenu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/add_alarm"
android:icon="@drawable/add_alarm"
android:orderInCategory="100"
android:showAsAction="ifRoom"
android:title="@string/add_alarm_title"/>
<item
android:id="@+id/action_settings"
android:showAsAction="ifRoom"
android:title="@string/menu" >
</item>
感谢。
答案 0 :(得分:0)
我看到一些活动使用不同的主题。您希望ActionBar的所有活动必须由Theme.Sherlock扩展。