setting menu item's title appears as all cap on android

纵然是瞬间 提交于 2019-12-12 02:29:48

问题


I have a menu item as explained in How do I add a button as a menu item?. When I use an icon, I can click on the icon fine. But when I use an actionLayout, I am getting no response on click. Here is the button the actionLayout points to:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/my_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_marginRight="15dp"
        android:background="#999999"
        android:text="Apple" />

</RelativeLayout>

Any ideas how to fix this problem? The idea is to use my own view instead of a drawable.


回答1:


I cannot speak from experience but I have found this code fragment that might help you. (I believe the actionbar item is an icon first an actionbar when activated)

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.options, menu);
  MenuItem menuItem = menu.findItem(R.id.actionItem);
  ...

  menuItem.setOnActionExpandListener(new OnActionExpandListener() {
  @Override
  public boolean onMenuItemActionCollapse(MenuItem item) {
      // Do something when collapsed
      return true;  // Return true to collapse action view
  }

  @Override
  public boolean onMenuItemActionExpand(MenuItem item) {
      // Do something when expanded
      return true;  // Return true to expand action view
  }
  });

}

Link: http://developer.android.com/guide/topics/ui/actionbar.html




回答2:


Actually I figure it out. I use

<Button  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:layout_marginRight="15dp"
    android:background="#999999"
    android:text="Apple" />

with getActionView



来源:https://stackoverflow.com/questions/17538218/setting-menu-items-title-appears-as-all-cap-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!