0

再次,我在这里使用动作栏夏洛克不知所措..似乎我添加的按钮根本没有出现。这是我已经做过的

在我的清单中

<activity android:name=".RecipeBookList"  android:theme="@style/SherlockCustom"></activity>

在我的styles.xml中

<style name="SherlockCustom" parent="@style/Theme.Sherlock.Light">
        <item name="abHeight">25dip</item>
        <item name="abBackground">#ffffff</item>
        <item name="abDisplayOptions">useLogo|showHome|homeAsUp|showTitle</item>
    </style>

在我的 RecipeBookList.java

public class RecipeBookList extends FragmentActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.recipebooklist);

          GridView gridview = (GridView) findViewById(R.id.gridview);
          gridview.setAdapter(new ImageAdapter(this));

          gridview.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                  //Toast.makeText(RecipeBookList.this, "" + position, Toast.LENGTH_SHORT).show();
                  displayRecipeList(""+position);
              }
          });
       }

       @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.mainmenu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Toast.makeText(this, "Just a test", Toast.LENGTH_SHORT).show();
        return true;
    }

在我的 mainmenu.xml 中

<item android:id="@+id/preferences" android:title="Search" android:showAsAction="always|withText" android:icon="@drawable/ab_search"></item>

但是搜索按钮根本没有出现在操作栏中。实际上它根本没有出现在任何地方。我哪里出错了?

4

2 回答 2

0

您需要使用此处提供的片段支持包:http : //beta.abs.io/ 然后修复您的导入以使用 ActionBarSherlock 等效项,并使用 getSupportMenuInflater() 而不是 getMenuInflater()

编辑:可能应该提到,这是如果您使用的是 ABS4。

于 2012-02-19T00:58:44.027 回答
0

尝试使用这个

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    //Used to put dark icons on light action bar

    menu.add("Search")
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    return true;
}   

您也可以在他们的页面和带有示例的 APK 中查看其代码: https://github.com/JakeWharton/ActionBarSherlock/blob/master/samples/demos/src/com/actionbarsherlock/sample/demos/ActionItems。爪哇

于 2012-12-07T11:37:01.997 回答