why `ifroom` does not work - android studio -
hi there try set ifroom
in menu item. can see in code try possible senario (please see each showasaction
item
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".mainactivity"> <item android:id="@+id/action_forward" android:title="forward" android:icon="@drawable/ic_action_arrow_forward" android:showasaction="ifroom" ></item> <item android:id="@+id/action_zoom_in" android:title="zoom in" android:icon="@drawable/ic_action_zoom_in" android:showasaction="ifroom|withtext" ></item> <item android:id="@+id/action_home" android:title="home" android:icon="@drawable/ic_action_home" app:showasaction="ifroom|withtext" ></item> <item android:id="@+id/action_refresh" android:title="refresh" android:icon="@drawable/ic_action_refresh" app:showasaction="ifroom" ></item> <item android:id="@+id/action_zoom_out" android:title="zoom out" android:icon="@drawable/ic_action_zoom_out" showasaction="ifroom" ></item> <item android:id="@+id/action_back" android:title="back" android:icon="@drawable/ic_action_arrow_back" app:showasaction="always" ></item> </menu>
but show action_back
, action_home
in main page.
i noob in android studio think error related width of menu. (it not 100% width)
please see main_activity.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".mainactivity"> <include android:id="@+id/tool_bar_bottom" layout="@layout/tool_bar_bottom" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_gravity="center" /> </linearlayout>
and tool_bar_bottom.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.toolbar android:layout_height="wrap_content" android:layout_width="match_parent" android:background="@color/colorprimary" android:elevation="2dp" android:theme="@style/base.themeoverlay.appcompat.dark" xmlns:android="http://schemas.android.com/apk/res/android" />
i think structure true , values of layout_width
match_parent
why ifroom
not work me?
android show menu if set "showasaction" attribute "always". if set "ifroom", displayed if actionbar has room display menu item, else display overflow icon.
in case, seeing "action_back" because has "always". "action_home" becuase there room 1 icon , first item has "app:showasaction" attribute. others have "android:showasaction" attribute. more explanation on behaviour below.
if app using support library compatibility on versions low android 2.1, showasaction attribute not available android: namespace. instead attribute provided support library , must define own xml namespace , use namespace attribute prefix. (a custom xml namespace should based on app name, can name want , accessible within scope of file in declare it.)
Comments
Post a Comment