Android Actionbar Menu Item Title shown in Tablet not in Phone - android

Menu.xml
<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.kent.service.engg.controllers.CaseDetailsActivity">
<item android:id="#+id/title_bar_home"
android:icon="#drawable/action_home_icon"
android:title="Home"
app:showAsAction="ifRoom" />
<item android:id="#+id/title_bar_setting"
android:icon="#drawable/action_settings_icon"
android:title="Setting"
app:showAsAction="ifRoom|withText"/>
</menu>
This code working fine in Tablet but it is not working in Phone.

<item android:id="#+id/title_bar_setting"
android:icon="#drawable/action_settings_icon"
android:title="Setting"
app:showAsAction="ifRoom|withText"/>
Here attribute value : "ifRoom" will neglate text if there is no space in actionbar of phone

Related

Navigation menu items with dropdown menu Android

I'm using Navigation Drawer. I've used a spinner layout in a menu item, but it looks bad. I'm trying to have a view like this, but IDK how.
So when I press PRODUCT, a dropdown submenu appears.
I've tried this code to do so but it's not working.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:showIn="navigation_view">
<group android:checkableBehavior="single"
>
<item
android:id="#+id/nav_home"
android:checkable="true"
android:icon="#drawable/ic_outline_home_24"
android:title="#string/home" />
<item
android:id="#+id/nav_products"
android:checkable="true"
android:visible="true"
android:actionLayout="#android:layout/simple_spinner_dropdown_item"
android:icon="#drawable/ic_outline_shopping_bag_24"
app:showAsAction="collapseActionView"
android:title="#string/products" >
<menu>
<item
android:id="#+id/fire_alam"
android:title="#string/fire_alarms"
android:checkable="true"
app:showAsAction="never"
/>
<item
android:id="#+id/fire_fighting"
android:checkable="true"
app:showAsAction="never"
android:title="#string/fire_fighting"/>
</menu>
</item>
<item
android:id="#+id/nav_serv"
android:checkable="true"
android:icon="#drawable/ic_outline_room_service_24"
android:title="#string/services" />
</group>
</menu>
You can use ExpandableListView
Check:- https://www.journaldev.com/9942/android-expandablelistview-example-tutorial
Also you can use it in NavigationView
Check:-
https://www.journaldev.com/19375/android-expandablelistview-navigationview

when i set icon to drawer menu then the drawer menu become slow in android

I'm new in Android
when i set icon in drawer_menu.xml code then after when i open the
navigation drawer menu it open slowly why?
If any one have answer to this question or ever faced this type of
issues then plz reply to this question.
Here is my drawer_menu.xml code.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/home_id"
android:icon="#drawable/home"
android:title="Home"></item>
<item
android:id="#+id/id_setting"
android:icon="#drawable/setting"
android:title="Settings"></item>
</group>
<item android:title="Others">
<menu>
<item
android:id="#+id/notifications"
android:icon="#drawable/noti"
android:title="Notifications"></item>
<item
android:id="#+id/about_us"
android:icon="#drawable/aboutus"
android:title="About us"></item>
</menu>
</item>
</menu>
What is the size of icon?
use 300*300

How to show always 5 items in Action mode menu like WhatsApp in Android toolbar

<?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:id="#+id/menu_reply"
android:icon="#drawable/ic_reply_white_24dp"
android:title="Reply"
app:showAsAction="always" />
<item
android:id="#+id/menu_favourite"
android:icon="#drawable/ic_grade_white_24dp"
android:title="Favourite"
app:showAsAction="always" />
<item
android:id="#+id/menu_info"
android:icon="#drawable/ic_info_outline_white_24dp"
android:title="Info"
android:visible="false"
app:showAsAction="always" />
<item
android:id="#+id/menu_delete"
android:icon="#drawable/ic_delete_white_24dp"
android:title="Delete"
app:showAsAction="always" />
<item
android:id="#+id/menu_copy"
android:icon="#drawable/ic_content_copy_white_24dp"
android:title="Copy"
app:showAsAction="always" />
<item
android:id="#+id/menu_right_arrow"
android:icon="#drawable/ic_arrow_right_bold_white_24dp"
android:title="Forward"
app:showAsAction="always" />
<item
android:id="#+id/menu_message"
android:icon="#drawable/ic_arrow_right_bold_white_24dp"
android:title="Message xyz"
app:showAsAction="always" />
<item
android:id="#+id/menu_call"
android:icon="#drawable/ic_arrow_right_bold_white_24dp"
android:title="Call xyz"
app:showAsAction="always" />
</menu>
I'm using Action mode menu while long click on list item. It is always showing max 2 items, even it has space to show more items in Action mode menu. I'm assigning android:showAsAction = "always" for all the items. I'm expecting to design screen like WhatsApp long press showing 5 items with icons.
Use android:showAsAction="always" property along with app:showAsAction="always".
<item
android:id="#+id/menu_reply"
android:icon="#drawable/ic_reply_white_24dp"
android:title="Reply"
app:showAsAction="always"
android:showAsAction="always" />
Use import android.support.v7.view.ActionMode and
yourActionMode = startSupportActionMode(mActionModeCallback)
it solves this problem.

AppCompat Toolbar not showing icon set in menu XML

I am unable to get the icon to show with or without the title text using the AppCompat Toolbar. The title text appears fine, but there is no icon shown at all.
The icon and title text are defined in a menu.xml using the following xml:
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="ui.CreateProfileActivity">
<item
android:id="#+id/create_profile_submit"
android:title="#string/create_profile_submit"
app:icon="#drawable/ic_done_white_24dp"
app:showAsAction="always"/>
</menu>
In my styles.xml I've set the icon color to be white explicitly (the background of the Toolbar is blue):
<item name="actionBarIconColor">#fff</item>
This is the toolbar_actionbar.xml that is used to display the Toolbar:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:theme="#style/ActionBarThemeOverlay"
app:popupTheme="#style/ActionBarPopupThemeOverlay"
android:id="#+id/toolbar_actionbar"
android:background="?attr/colorPrimaryDark"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
When I launch the application in either portrait or landscape, the icon does not appear.
How do I get the Toolbar to either show:
The icon and text
Only the icon (See Edit Below)
EDIT: 2014.12.14
I was able to get the icon, and only the icon, to show by updating the menu.xml "icon" property to use "android" instead of "app". The new xml is as follows:
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="ui.CreateProfileActivity">
<item
android:id="#+id/create_profile_submit"
android:title="#string/create_profile_submit"
android:icon="#drawable/ic_done_white_24dp"
app:showAsAction="always"/>
</menu>
I am still unable to get the icon AND text to show at the same time in portrait mode. It does show both in landscape mode.
Get the reference of the toolbar within your activity and set the Icon or most of its parts
ToolBar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
toolbar.setLogo(R.drawable.yourdrawable);
toolbar.setTitle("Your Title");
toolbar.setSubtitle("list");
toolbar.setNavigationIcon(R.drawable.drawer_icon);
I know this is beyond what is requested of the question, buh i wanted to shed more light on what you can
Try out to solve the problem.
I hope this helps somebody.
try this menu: for toolbar
`
<item
android:id="#+id/menu_overflow"
android:enabled="true"
android:icon="#drawable/ic_menu_moreoverflow_mtrl_alpha"
app:showAsAction="always"
android:title="">
<menu>
<item
android:id="#+id/action_more"
android:icon="#drawable/ic_more_apps"
android:orderInCategory="100"
android:showAsAction="never"
android:title="More apps"/>
<item
android:id="#+id/action_rate"
android:icon="#drawable/ic_rating"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Rate this app"/>
<item
android:id="#+id/action_feedback"
android:icon="#drawable/ic_feedback"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Feedback"/>
<item
android:id="#+id/action_share"
android:icon="#drawable/ic_share"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Share this app"/>
</menu>
</item>
`
try this menu for actionbar
`
<item
android:id="#+id/menu_overflow"
android:enabled="true"
android:icon="#drawable/ic_menu_moreoverflow_mtrl_alpha"
android:showAsAction="always"
android:title="">
<menu>
<item
android:id="#+id/action_more"
android:icon="#drawable/ic_more_apps"
android:orderInCategory="100"
android:showAsAction="never"
android:title="More apps"/>
<item
android:id="#+id/action_rate"
android:icon="#drawable/ic_rating"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Rate this app"/>
<item
android:id="#+id/action_feedback"
android:icon="#drawable/ic_feedback"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Feedback"/>
<item
android:id="#+id/action_share"
android:icon="#drawable/ic_share"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Share this app"/>
</menu>
</item>
`
I think this is so late. But this code works well. You can try this.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
if (menu instanceof MenuBuilder) {
((MenuBuilder) menu).setOptionalIconsVisible(true);
}
getMenuInflater().inflate(R.menu.menu_quran, menu);
return true;
}

Icon of the menu item doesn't show up in the Action Bar if it is from app drawable folders

When I do like this it works:
<item
android:id="#+id/menu_show_location"
android:title="#string/menu_show_location"
android:icon="#android:drawable/ic_dialog_map"
app:showAsAction="always"/>
But if I take icon from app drawable:
<item
android:id="#+id/menu_show_location"
android:title="#string/menu_show_location"
android:icon="#drawable/ic_action_place"
app:showAsAction="ifRoom"/>
the menu item doesn't show up nor in the menu nor in the action bar either.
Full 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">
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
<item
android:id="#+id/menu_show_location"
android:title="#string/menu_show_location"
android:icon="#android:drawable/ic_dialog_map"
app:showAsAction="always"/>
<!--android:icon="#drawable/ic_action_place"-->
</menu>
What can be a problem?
Try this,
<item
android:id="#+id/menu_show_location"
android:title="#string/menu_show_location"
<!--android:icon="#android:drawable/ic_dialog_map"-->
<!-- need to add an order-->
android:orderInCategory="200"
android:icon="#drawable/ic_action_place"
app:showAsAction="always"/>
In situations like that changing icon color or app theme may helps ))

Categories

Resources