Action Bar not displaying menu item with both icon and text - android

Despite there being enough space in the action bar , only the icon is being displayed, even when I am using
app:showAsAction= "always|withText"
Full code:
<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="com.ishaan.admin.notify.Profile">
<item android:id="#+id/action_logout"
android:title="Logout"
android:icon="#drawable/logout_icon"
app:showAsAction= "always|withText" />
</menu>

It is known thing on the Android 4.0 and discussed ealier
Your can find solution here:
android 4.0, text on the action bar NEVER shows

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/toolbar_right_button"
android:orderInCategory="1"
android:title="Text"
app:actionLayout="#layout/menu_item_1"
app:showAsAction="ifRoom|withText"/>
</menu>
and in Layout create Layout File menu_item_1.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/logout_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#drawable/ic_toolbar_locked"
android:gravity="center_vertical"
android:text="Text"
android:textColor="#color/PrimaryColour"/>
</RelativeLayout>

Related

(android) Why doesn't app:actionLayout="" work?

Hi
I'm using Navgation Drawer.
I want to change from text to text and icon at overflow menu items.
So i used 'android:icon' and 'android:title' in menu.xml. But Anything is not displayed.
To be exact, I could only see text.
and
I used android:actionLayout="#layout/overflow_menu_item". In overflow_menu_title, Text and Icon are defined.
But It dosen't work, too
I don't no why it dosen't work.
How to set Text and icon in overflow menu item?
I searched a lot but it didn't help.
plz help me...
Here is Code
overflow_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<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=".MovieList">
<item
android:id="#+id/menu_movie"
android:orderInCategory="150"
android:icon="#drawable/ic_search_black_24dp"
android:title="setting1"
android:actionLayout="#layout/overflow_menu_title"
app:showAsAction="never" />
<item
android:id="#+id/menu_gallery"
android:orderInCategory="150"
android:title="setting2"
android:icon="#drawable/ic_search_black_24dp"
app:showAsAction="never" />
<item
android:id="#+id/settings3"
android:orderInCategory="150"
android:icon="#drawable/ic_search_black_24dp"
android:title="setting2"
app:showAsAction="never" />
</menu>
overflow_menu_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center_vertical"
android:padding="2dp"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/colorPrimaryDark">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/ic_15"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MOVIE"
android:textSize="24dp"/>
</LinearLayout>
You can't create a custom layout for menu item using android:actionLayout for items that are not on the action bar.
In other meaning, you can't set android:actionLayout for non-action items that are in the overflow menu items.

Does android:actionLayout in Menu Folder to Create Android Action bar not work?

I'm creating an Android Action Bar using menu directory. While I was creating a new bar, I wanted to customize this action bar, so I added action-layout in one of items in xml file under menu directory. here is what I did
menu_main.xml(under menu directory)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:orderInCategory="101"
android:id="#+id/menu_refresh"
android:title="refresh"
android:icon="#drawable/menu_refresh"
app:showAsAction="always"/>
<item
android:orderInCategory="102"
android:id="#+id/menu_search"
android:title="search"
app:showAsAction="always"
android:actionLayout="#layout/search_layout"/>
<item
android:orderInCategory="103"
android:id="#+id/menu_setting"
android:title="setting"
android:icon="#drawable/menu_settings"
app:showAsAction="always"/>
</menu>
in second item, i added actionLayout and search_layout.xml is just simeple LinearLayout
with TextView and EditText.
search_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="search"
android:textSize="16dp"
android:textColor="#ffad8745"/>
<EditText
android:id="#+id/editText"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:background="#ffad8745"/>
</LinearLayout>
My expectation was that the first and third item show icons whereas second item shows me a layout that I defined, but here's what i got: only the title that I defined in menu_main.xml.
I eventually made an action bar that I wanted, but I still don`t quiet understand why the way initially tried does't work. please help me out. thank you

How to increase the menuitem width in android while using Actionbar

I have a problem to increase the width of MenuItem in Action bar, it take the fixed width. Below is screen shot,
and want to achieve the below one,
Below is the code:
search_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:background="#drawable/search_view_background"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content">
<TextView android:layout_width="0dp"
android:padding="10dp"
android:layout_weight="1"
android:text="Search Product"
android:textColor="#color/grey"
android:gravity="center_vertical"
android:drawableEnd="#drawable/ic_search"
android:drawableRight="#drawable/ic_search"
android:drawablePadding="20dp"
android:textSize="#dimen/text_size_14sp"
android:layout_height="match_parent"/>
</LinearLayout>
home_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/search"
android:onClick="onClickSearchButton"
android:orderInCategory="1"
android:title="#string/Search"
app:actionLayout="#layout/search_layout"
app:showAsAction="always"/>
<item
android:id="#+id/action_cart"
android:icon="#drawable/ic_menu_cart"
android:orderInCategory="2"
android:title="#string/action_cart"
app:showAsAction="always"/>
<item
android:id="#+id/overflow"
android:icon="#drawable/ic_menu_notifications"
android:orderInCategory="3"
android:title="#string/overFlowMenu"
android:visible="false"
app:showAsAction="always"/>
Please give your suggestion, how to fix this problem.
Thanks
Did it with a Hack.
I know it's not the best or even good solution but I did it with an hack.
searchItem.getActionView().findViewById(R.id.text).setMinimumWidth(width);
You can pass a particular width to the view so that it will take at-least that much space.

android - Set switch button into action bar with showAsAction="never"

I want to put a switch button into MenuItem with showAsAction="never" but it's not working. Here is my layout
<?xml version="1.0" encoding="utf-8"?>
<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="com.trietnhm.multipleactivities.MainActivity"
>
<item
android:id="#+id/action_about"
android:orderInCategory="0"
app:showAsAction="never"
android:title="About"/>
<item
android:id="#+id/action_change_theme"
android:orderInCategory="3"
app:actionLayout="#layout/switcher"
app:showAsAction="never"
android:title="" />
<item
android:id="#+id/action_change_delimeter"
android:orderInCategory="2"
app:showAsAction="never"
android:title="Change Delimeter"/>
</menu>
This my Switch button
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.SwitchCompat
android:id="#+id/switchForActionBar"
android:layout_width="70dp"
android:layout_height="50dp"
android:scaleX="1.3"
android:scaleY="1.3"
android:switchMinWidth="45dp"
android:paddingTop="6dp" />
</RelativeLayout>
When I run the app and it's not show anything. Here the image https://drive.google.com/file/d/0B5zsq6J-qyY5bF8tYnBKVy11OHM/view?usp=sharing
Any help I would be appreciated. Thanks all.
android:showAsAction
never :
Never place this item in the app bar. Instead, list the item in the
app bar's overflow menu.
Of course, It won't show up. Perhaps you should use other options to show, always or ifRoom.
This line code
android:orientation="vertical"
is used with LinearLayout not with RelativeLayout
why are you using app:showAsAction="Never"?? for that you can also use app:showAsAction="ifRoom" or app:showAsAction="ifRoom|collapseActionView"

Custom tab indicator view

I want to reproduce this tab indicator structure (screen is from nova launcher): a dropdown menu and an arrow in the right bottom corner.
I have no problem about code but i can't reproduce this appearance.
I tried this:
mBar.addTab(mBar.newTab().setText(ctx.getString(R.string.tab_actions)).setTabListener(this).setCustomView(R.layout.navigation_spinner));
where mBar is sherlock support actionBar.
This is my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_margin="-10dp"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<Button android:id="#+id/button1" android:layout_width="match_parent"
android:layout_height="match_parent" android:text="Button" />
</LinearLayout>
and this is my result:
The problem is that the button in the central tab doesn't fill the tab indicator. How can i set a custom view that perfectly fill the indicator without margin or padding? Or i have to approach this in a different way to have the a result like the firs screen? Thanks in advice
What you are trying to do is really complicated, and will be hard to achieve.
If you want drop down menus you can try those :
menu/options.xml:
<item
android:icon="#drawable/ic_menu_sort"
android:showAsAction="ifRoom">
<menu>
<item
android:id="#+id/menuSortNewest"
android:title="Sort by newest" />
<item
android:id="#+id/menuSortRating"
android:title="Sort by rating" />
</menu>
</item>
Second option:
menu/options.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menuSort"
android:showAsAction="ifRoom"
android:actionLayout="#layout/action_sort" />
</menu>
layout/action_sort.xml:
<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_menu_refresh"
android:entries="#array/order" />
Docs for menu resources - http://developer.android.com/guide/topics/resources/menu-resource.html

Categories

Resources