Android ActionBar appears after clicking settings - android

Code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.start_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
start_activity.actions.xml:
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
android:showAsAction="always"
/>
<item
android:id="#+id/action_collection"
android:title="#string/action_collection"
android:icon="#drawable/ic_action_collection"
android:showAsAction="always"
/>
My menu appears only after clicking settings button. It's not visibile on launch. How to change it ?

If You have extend the activity to android.app.Activity; then the menu xml you have should work.
If your using support library android.support.v7.app.ActionBarActivity then to display the action menus in action bar, change your menu xml like below..
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
custom:showAsAction="always"/>
<item
android:id="#+id/action_collection"
android:title="#string/action_collection"
android:icon="#drawable/ic_action_collection"
custom:showAsAction="always"/>
</menu>

Related

Continuous Search menu item not showing properly in android

menu_main.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">
<item android:id="#+id/search"
android:orderInCategory="100"
android:title="search"
android:icon="#drawable/ic_search"
app:showAsAction="always"/>
<item
android:id="#+id/refresh"
android:icon="#drawable/ic_refresh_black_24dp"
android:orderInCategory="100"
app:showAsAction="ifRoom|collapseActionView"
android:title="refresh" />
</menu>
MainActivity.java:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
menu.findItem(R.id.search);
return super.onCreateOptionsMenu(menu);
}
First time If I am open my app below one is my screen
First time my screen was looks like this
Next time onward my screen looks like this
Next time on-wards My screen was looking like this

Android: Action button icons always appear in overlay

Action items always appear in overlay. Here is the code:
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/action_create_order"
android:title="#string/action_create_order"
android:icon="#drawable/ic_event_black_18dp"
android:orderInCategory="1"
app:showAsAction="always" />
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
and in the main activity:
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}
Shouldn't the first item appear on the action bar because of "app:showAsAction="always" ?
Use this inside your item ,to display in Action bar
app:showAsAction="always"
When you dont want to display item in Action bar
app:showAsAction="never"
Try this piece of code , instead of your creating Option Menu
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
If it is for fragments
custom namespace will prevent showAsAction from showing. so
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_create_order"
android:title="#string/action_create_order"
android:icon="#drawable/ic_event_black_18dp"
android:orderInCategory="1"
android:showAsAction="always"
android:icon="#android:drawable/ic_menu_add" />
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>

Android Action bar not showing Icons

How can i display Icons in Actions bar, here is my code,
<?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/search_icon"
android:icon="#drawable/ic_action_search"
android:showAsAction="always"
android:orderInCategory="0"
android:title="Search" >
</item>
</menu>
and
#Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater mif = getMenuInflater();
mif.inflate(R.menu.custom_action_bar,menu);
return super.onCreateOptionsMenu(menu);
}
Thanks for Help !
If using app compat use app:showAsAction
<item android:id="#+id/search_icon"
android:icon="#drawable/ic_action_search"
app:showAsAction="always"
android:orderInCategory="100"
android:title="Search" >
</item>
In Manifest.xml File
<activity android:name="your activity name"
android:theme="#style/Theme.Holo.Light"></activity>

Actionbar action button shown as drop down item instead of button

Im trying to remove one of my action bar items(the settings menu) and add another one but its not adding the right icon/action to the action bar.
my layout file is as follows
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:icon="#drawable/settings"
android:showAsAction="always" />
</menu>
and im initializing it like this
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDefaultDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(true);
actionBar.setTitle(mTitle);
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
it shows the three android dots instead of my own icon(it also puts it in the dropdown
i want to change the dots in the red circle
what am i doing wrong
your layout file should be like this
<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:icon="#drawable/settings"
app:showAsAction="always" />
very easy ,Replace your layout code:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:icon="#drawable/settings"
android:showAsAction="never" />
</menu>

how to create menu android with sherlock

I don't know how to create the bottom menu with sherlock on the button with the ActionBarSherlock, while my top menu is ok when created with sherlock.
I want the light style for my menu but I don't know how to create it with sherlock.
My code:
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.menu, menu);
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.submenu, menu);
return super.onCreateOptionsMenu(menu);
}
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_item"
android:showAsAction="always"
android:title="settings"
android:icon="#drawable/advancedsettings" >
<menu>
<item
android:id="#+id/removerss"
android:showAsAction="always"
android:icon="#drawable/remove"
android:title="Remove Rss" />
<item
android:id="#+id/addrss"
android:showAsAction="always"
android:title="Add Rss"
android:icon="#drawable/add" />
</menu>
</item>
</menu>
But this menu isn't connected with the style sherlock. So how can I create this menu with sherlock. Please if you can give some code to do it simple.

Categories

Resources