我将 SherlockActionBar 添加到我的项目中,添加了一些菜单项,它在模拟器 (4.0.3) 中运行良好,但在我的手机 (Galaxy S3) 上不起作用;它只是没有出现。
我的目标是 15,清单中的最低 sdk 版本为 9:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/dimmiicon"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.Light.DarkActionBar" >
代码相当简单,但也许我遗漏了一些东西。相关位...
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.MenuItem;
public class Launcher extends SherlockFragmentActivity implements OnUserAuthenticatedListener, OnDialogChatterListener, OnAnimationCompleteListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
final ActionBar ab = getSupportActionBar();
ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ab.setCustomView(R.layout.title_bar);
ab.setStackedBackgroundDrawable(getResources().getDrawable(R.drawable.titlebarbackground));
TextView txt = (TextView) findViewById(R.id.myTitle1);
Typeface font = Typeface.createFromAsset(getAssets(), "caviar_dreams_bold.ttf");
txt.setTypeface(font);
TextView txt2 = (TextView) findViewById(R.id.myTitle2);
Typeface font2 = Typeface.createFromAsset(getAssets(), "caviardreams.ttf");
txt2.setTypeface(font2);
}
@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
getSupportMenuInflater().inflate(R.menu.commonmenus, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
return false;
case R.id.search_for_product:
performProductReview(findViewById(android.R.id.content));
return true;
case R.id.search_for_business:
performCompanyReview(findViewById(android.R.id.content));
return true;
case R.id.search_for_service:
performServiceReview(findViewById(android.R.id.content));
return true;
case R.id.search_for_person:
performPersonReview(findViewById(android.R.id.content));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
和 commonmenus.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/menu_settings"/>
<item android:id="@+id/search_for_product" android:showAsAction="never" android:orderInCategory="10" android:title="@string/menu_search_for_product"></item>
<item android:id="@+id/search_for_business" android:showAsAction="never" android:orderInCategory="11" android:title="@string/menu_search_for_business"></item>
<item android:id="@+id/search_for_service" android:showAsAction="never" android:orderInCategory="12" android:title="@string/menu_review_service"></item>
<item android:id="@+id/search_for_person" android:showAsAction="never" android:orderInCategory="14" android:title="@string/menu_review_person"></item>
<item android:id="@+id/view_my_reviews" android:showAsAction="never" android:orderInCategory="15" android:title="@string/menu_view_my_reviews"></item>
</menu>
我正在使用 sherlock 操作栏使用一些自定义字体来自定义标题,并且在模拟器和手机上都可以使用,但菜单只显示在模拟器上。我确实尝试使用注释掉的自定义字体代码,它没有任何区别。
只是我很清楚:3个菜单点甚至没有出现。
在花了几个小时搜索和寻找线索之后,我不知所措。任何见解将不胜感激。