android 栏 Sherlock 添加按钮

发布于 2025-01-06 06:13:48 字数 1915 浏览 0 评论 0原文

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

这是我已经在清单

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

、styles.xml 和 RecipeBookList.java

<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>

以及

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>

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

again, i'm at loss using action bar sherlock here.. it seems the button I added doesn't appear at all. here's what i already did

in my manifest

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

and in my 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>

and in my 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;
    }

aind in my mainmenu.xml

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

but the search button doesn't appear in the action bar at all.. in fact it doesn't appear anywhere at all. where did i went wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

禾厶谷欠 2025-01-13 06:13:48

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

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

You need to use the fragment support package provided here: http://beta.abs.io/
Then fix your imports to use the ActionBarSherlock equivelants, and use getSupportMenuInflater() instead of getMenuInflater()

Edit: Should probably mention, this is if you are using ABS4.

与风相奔跑 2025-01-13 06:13:48

尝试使用这个

@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.java

try to use this

@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;
}   

Also you have in their page and APK with samples and you can check its code here:
https://github.com/JakeWharton/ActionBarSherlock/blob/master/samples/demos/src/com/actionbarsherlock/sample/demos/ActionItems.java

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文