I have created a sample android application that just displays some text and i can see that the menu bar at the top of the activity contains name of the application but not the icon of the application. The menu is also very thin just containing application name with a small font. Going through various tutorial i found that we have to select a particular menu style while creating the application to have a menu that contains both application name and icon, but my application just contains application name and the menu is very thin. Is it possible to increase the menu height now and add application icon to it dynamically or by making some changes in menu xml file?
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/app_name" android:icon="#drawable/ic_launcher"
android:title="My App" />
</menu>
If you want to customize the ActionBar, here you are a complete tutorial for it:
How can I implement custom Action Bar with custom buttons in Android?
It's very good an complete for customizing almost everything, so I recommend it to you.
Even tough, I ask you to change your question in order to make more clear the target of it, now you know what you were triying to mean ;)
<menu xmlns:tools="schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="com.example.sample.getMsgActivity"
xmlns:yourapp="http://schemas.android.com/apk/res-auto">
<!-- Search, should appear as action button -->
<item android:id="#+id/action_write"
android:icon="#drawable/ic_action_refresh"
android:title="#string/action_write"
yourapp:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_read"
android:title="#string/action_read"
yourapp:showAsAction="never" />
REMEMBER: clean, then build. it should work then.
Related
i am using the Support Library Navigation Drawer and I want to customize it.
My Current Menu looks like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?android:attr/activatedBackgroundIndicator">
<group
android:id="#+id/DrawerMainGroup"
android:checkableBehavior="single"
android:background="?android:attr/activatedBackgroundIndicator"
>
<item
android:id="#+id/drawer_home"
android:checked="true"
android:icon="#drawable/ic_home"
android:title="#string/home"
/>...
I want to have another icon on this. Do you think it is possible?
I searched the Web and could not fin anything useful for me.
Both images will be dynamically loaded. For example:
I have a app where i can get videos,pictures etc. That is the first Icon. Next to this, there should be a icon if this site is on homescreen or not.
Like: (IconType)(IconOnHome) Text
I don't know if this is even possible. I found app:actionlayout already, but i am not sure if I could load different images in to the xml.
I have an application without an appbar. Now I want to put 3 Buttons into a menu. I have seen the option to create a toolbar and then add the items programmaticlly. But first I would prefer not to have a bar but just the menu.
I know that that isn´t really important because I can make the bar transparent.
And Second I really don´t want to add the items programmatically. (But defigned in xml.) Is this possible, are there better ways and how can I do it?
If "By the menu" you mean, the overflow menu that exists in the app bar then you can not just the add the menu that way. The app bar or toolbar has to be there to contain that overflow menu. But for giving that sort of effect as you also mentioned you can have the toolbar transparent or you can look into the PopUpMenu, http://developer.android.com/guide/topics/ui/menus.html,
this way you can hide your app bar and can give a separate button which will call PopUpMenu, its going to give you same overflow menu effect.
Regarding your 2nd requirement of putting menu in xml, if i am getting it correct you can have your menu defined like this,
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/phone"
android:title="#string/phone"
android:icon="#drawable/phone"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/computer"
android:title="#string/computer"
android:icon="#drawable/computer"
android:showAsAction="ifRoom|withText"
/>
</menu>
You need your CSS anymets revised.
Please consider this codings:
style {template.css}
I think you'll find those are the exact answer.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:compat="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_chat"
android:icon="#drawable/ico_enter_chat"
android:title="Enter Chat"
compat:showAsAction="always|withText" />
<item android:id="#+id/action_map"
android:icon="#drawable/ico_map"
android:title="Users Map"
compat:showAsAction="always" />
<item android:id="#+id/action_logout"
android:icon="#drawable/ico_log_out"
android:title="Log Out"
compat:showAsAction="always" />
</menu>
Here is my menu XML file, in theory it should display two icons as single icons and first icon with title too.
However, in app it doesn't display title, here is screencap:
So why doesn't it display "title" ?
Source:
http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems
If your menu item supplies both a title and an icon—with the title and icon attributes—then the action item shows only the icon by default.
If you want to display the text title, add "withText" to the showAsAction attribute.
Note: The "withText" value is a hint to the action bar that the text title should appear. The action bar will show the title when possible, but might not if an icon is available and the action bar is constrained for space.
The Android system thought that there is no enough room to display the title of the menu item completely, so it hides the title (although there might be enough room, but Android doesn't think so.) If you turn into landscape or run the app in a tablet, the title will show up.
This declares that the Search action should appear as an action button when room is available in the action bar, but the Settings action should always appear in the overflow. (By default, all actions appear in the overflow, but it's good practice to explicitly declare your design intentions for each action.)
https://developer.android.com/training/basics/actionbar/adding-buttons.html
This worked for me
app:showAsAction="ifRoom|withText"
appcompat_v7 > values > config.xml
<bool name="abc_config_allowActionMenuItemTextWithIcon">false</bool>
change
<bool name="abc_config_allowActionMenuItemTextWithIcon">true</bool>
I'm making an android app in Eclipse. I want to place a text or icon in the action bar, but when I am writing in menu.xml, which looks like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/createnew"
android:orderInCategory="1"
android:showAsAction="ifRoom"
android:title="CREATE"/>
</menu>
it puts it in the options menu. I want to separate it.
I see this in the app when I run it:
(sorry can't post pictures because I don't have enough rep)
I want to CREATE next to the option menu like this for example:
Since you are using the AppCompat Actionbar, you need to use a custom namespaced showAsAction attribute.
It should look something like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/createnew"
android:orderInCategory="1"
yourapp:showAsAction="ifRoom"
android:title="CREATE"/>
</menu>
Note that this uses yourapp:showAsAction instead of android:showAsAction. This is because the showAsAction attribute is not available on pre-Honeycomb devices and is provided by the support library.
For more information, read the Action Bar developer guide.
It's caused by this line
android:showAsAction="ifRoom"
That tells Android to put it up there if it's going to fit nicely. If you want it up there no matter the fit use
android:showAsAction="always"
In the Gmail app, the search bar moves all the way to the left when you click on the search icon. Does anyone know how to recreate this effect? The current way I have it, the icon expands when clicked, but doesn't move to the left like the Gmail app. Here is my menu xml file:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_search"
android:title="Search"
android:icon="#drawable/ic_menu_search"
android:showAsAction="ifRoom"
android:actionViewClass="android.widget.SearchView"
/>
</menu>
Take a look at this SO Question and see if that is what you're referring to:
Contextual Action Bar in Honeycomb
and
Contextual Action Bar in Honeycomb
The Gmail app seems to simply have a search icon in the menu and when you click on this it will add SearchView as the current navigation view with getActionBar.setCustomView().
There are a few gotchas when doing this, for example handling when it should be removed etc but if handled well it can lead to a nice user experience. But it may not be worth the hassle though, the regular expandable SearchView should be sufficient for most applications.