Android - squished icon in actionbar after support library update - java

I want to have a checkmark icon in the actionbar.
The code I'm using is:
In menu_actionbar.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:title=""
android:id="#+id/action_check"
android:icon="#drawable/ic_done_white_48dp"
android:orderInCategory="100"
app:showAsAction="always"/>
</menu>
In the activity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_actionbar, menu);
return true;
}
Here's what it's supposed to look like, and how it has looked for a while until some recent support library update (not sure which one exactly): correct
Here's what it looks like on the device now: incorrect

Related

open a menu from Image View

I have problem to set a menu.
I want to open a menu from an ImageView, because I want to use a specific image on the tool bar.
I can't found any tutorials
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater =getMenuInflater();
menuInflater.inflate(R.menu.days, menu);
return true;
}
Thanks in advance!
Do you want to create menu something like this?
Menu xml code: menu/days.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=".MainActivity">
<item
android:id="#+id/item_love"
android:title="Love"
android:icon="#drawable/baseline_favorite_border_white_48"
app:showAsAction="always">
</item>
<item
android:id="#+id/item_more"
android:title="More"
android:icon="#drawable/baseline_add_white_48"
app:showAsAction="always">
<menu>
<item android:id="#+id/sub_item_1"
android:title="Sub Item 1"
app:showAsAction="withText"
/>
<item android:id="#+id/sub_item_2"
android:title="Sub Item 2"
app:showAsAction="withText"
/>
<item android:id="#+id/sub_item_3"
android:title="Sub Item 3"
app:showAsAction="withText"
/>
</menu>
</item>
</menu>
Full source code: https://github.com/hiepxuan2008/basic-menu-android
Hope it will help you. Thanks!

How to change color in xml file?

I built a simple menu (That if I click "menu" option in my emulator on eclipse I will see it), and I have three options in this menu: About us, preferences and exit. Everyone of them are work and good, but I have a small problem.
The color of the menu is white, and the text is white too so I cant to see the text.
This is the XML code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:text="About Us"
android:id="#+id/aboutUs"
android:numericShortcut="1"
android:alphabeticShortcut="a" />
<item
android:text="Perferences"
android:id="#+id/perferences" />
<item
android:text="Exit"
android:id="#+id/exit" />
</menu>
Hope for answers and thanks in advance!
public boolean onCreateOptionsMenu(android.view.Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
MenuInflater blowUp = getMenuInflater();
blowUp.inflate(R.menu.cool_menu, menu);
return true;
}
Please add:
<item name="android:actionMenuTextColor">#color/any_color_you_want</item>
to your styles.xml

Search Action Item Missing in Action Bar

I am new to Android Development. I am following the Beginning Development Tutorial from the developer.android.com. Unfortunately, I'm stuck trying to add a Search Action Item to the Action Bar. This is my XML and the onCreateOptionsMenu that corresponds:
<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.example.test.MainActivity" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
app:showAsAction="always"/>
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never"/>
</menu>
.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
My drawable directories contains the ic_action_search.png for all the screen densities. Also, my SDK min is 8 and the target is 19. I have imported the v7.app.ActionBarActivity as well.
The setting and overflow menu show up, yet the Search is still missing. What am I doing wrong?
It could be because you are using the compatibility library in which case you need to add extra attributes to the menu XML file. This is my item for the search option...
<item android:id="#+id/options_menu_search"
android:title="#string/search"
android:icon="#android:drawable/ic_menu_search"
com.mycompany.myapp:showAsAction="ifRoom|collapseActionView"
com.mycompany.myapp:actionViewClass="android.support.v7.widget.SearchView" >
</item>
Notice the two lines which start with com.mycompany.myapp - those are necessary when using the compatibility menu options. Change that prefix to match your app's package name.

Can't display an icon in the actionbar

I'm trying to show a map icon downloaded from the official android developers source.
I did everything as it should, but the icon won't show.
Here is my xml file named main_activity_bar:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/mapIcon"
android:icon="#drawable/ic_action_map"
android:title="#string/mapIconTitle"
android:showAsAction="always"
/>
</menu>
Here is the main activity xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.gs.testApp.MainActivity"
tools:ignore="MergeRootFrame" />
and this is what I have in the java class:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater actionMenue = getMenuInflater();
actionMenue.inflate(R.menu.main_activity_bar, menu);
return super.onCreateOptionsMenu(menu);
}
Everything seems to be fine, but the icon wont show on the emulator. Here is a screenshot:
The minimum version is android 3.0
Why the icon is not showing? What Am I missing? I know that it is something really small, but I can't spot it.
Here is how I fixed it - in case that someone is facing the same issue.
I changed
android:showAsAction="always" to app:showAsAction="always" and I also placed the icon order android:orderInCategory="0" and the auto res xmlns:app="http://schemas.android.com/apk/res-auto" so now my xml looks like:
<?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="0"
android:id="#+id/mapIcon"
android:icon="#drawable/ic_action_map"
android:title="#string/mapIconTitle"
app:showAsAction="always"
/>
</menu>
I dont think an icon is shown in the overflow menu. Try changing your title to "t" or rotate the screen. See if the icon appears this way.

Menu icons won't appear

I'm trying to add some menu items with icons to a menu.
The items appear but without the icon on the left side of them, it's just the text...
By the way, I'm using the Holo Light theme...
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_market"
android:title="View on Play Store"
android:icon="#drawable/ic_playstore_colorful"/>
</menu>
Thanx upfront!
Okay so i found this android blog post, http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html and they mentioned how the whole menu paradigm is changing in ICS and they said to use the actionbar now, requires API 11 or later:
I have this in /res/menu/activity_main XML directory:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/firstmenu"
android:title="#string/menu_settings"
android:icon="#drawable/ic_launcher"
android:showAsAction="always|withText">
<menu>
<item android:id="#+id/submenu"
android:title="SubMenu">
</item>
</menu>
</item>
<item android:id="#+id/secondmenu"
android:title="seconditem"
android:icon="#drawable/ic_launcher"
android:showAsAction="always|withText">
</item>
</menu>
And this in source of course:
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main, menu);
return true;
}
Works pretty well and looks good.

Categories