Why does not show the action_call.title in the second device ??
I want to show the action_call.title on each device.
this device Android 5.1.1 (api22) 7"
this device Android 6.0 (api23) 5.96"
this is my 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">
<item
android:id="#+id/action_call"
android:icon="#drawable/call"
android:title="#string/action_call"
android:visible="true"
app:showAsAction="ifRoom|withText" />
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never" />
<item
android:id="#+id/action_info"
android:icon="#drawable/info2"
android:title="#string/action_info"
app:showAsAction="never|withText" />
</menu>
this is my onCreateOptionsMenu on MainActivity.java
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
MenuItem action_call = menu.findItem(R.id.action_call);
action_call.setTitle("+99");
return true;
}
Related
I want the menu items to show on action bar. There is a lot of space on the ActionBar, but still they don't show up. Every item shown as three dots, why?
.java file
public class GalleryActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery_layout);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
}
.xml file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:MissionAndroid="http://schemas.android.com/tools">
<item
android:id="#+id/facebookId"
android:title="facebook"
android:icon="#drawable/facebook"
MissionAndroid:showAsAction="always"/>
<item
android:id="#+id/shareId"
android:title="share"
android:icon="#drawable/share"
MissionAndroid:showAsAction="always"/>
<item
android:id="#+id/delete"
android:title="delete"
android:icon="#drawable/delete"
MissionAndroid:showAsAction="always"/>
<item
android:id="#+id/searchId"
android:title="search"
android:icon="#drawable/search"
MissionAndroid:showAsAction="ifRoom"/>
</menu>
Currently, you're using "http://schemas.android.com/tools" which does not offer the functionality you're looking for and your showAsAction modifiers are being ignored.
Try updating your main_menu.xml with the following:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:MissionAndroid="http://schemas.android.com/apk/res-auto">
...
</menu>
Better yet, to follow convention, replace MissionAndroid in this file with app:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/facebookId"
android:title="facebook"
android:icon="#drawable/facebook"
app:showAsAction="always"/>
...
</menu>
I created 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/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never" />
but, in my activity xml the menu doesn't appear!
So What can I do?
Thanks!
You need to override the onCreateOptionsMenu() method in your activity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu); // Specify your menu 'id' here
return true;
}
I write an option menu code with a tutorial.
and for some reason it didnt work.
my checker_page_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:MyApp="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/waiters_filtering"
android:title="#string/waiters"
MyApp:showAsAction="always"
/>
<item android:id="#+id/areas_filtering"
android:title="#string/waiters"
MyApp:showAsAction="always"
/>
<item android:id="#+id/tables_filtering"
android:title="#string/waiters"
MyApp:showAsAction="always"
/>
<item android:id="#+id/tapas_filtering"
android:title="#string/waiters"
MyApp:showAsAction="always"
/>
</menu>
and my totaly normal OnCreatOptinMenu in the MainActivity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.checker_page_menu, menu);
return true;
}
What seems to be the problem and why cant i see my optionMenu?
I'm following the google tutorial for action bars but the icons don't appear on it, this is the menu xml file:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_refresh"
android:icon="#drawable/ic_action_refresh"
android:title="refresh"
android:showAsAction="ifRoom"/>
<item android:id="#+id/action_settings"
android:icon="#drawable/ic_action_settings"
android:title="settings"
android:showAsAction="ifRoom"/>
<item android:id="#+id/action_compose"
android:icon="#drawable/ic_action_new"
android:title="add"
android:showAsAction="ifRoom"/>
</menu>
and this in my main acivity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_bar, menu);
return super.onCreateOptionsMenu(menu);
}
Use yourapp:showAsAction instead of android:showAsAction
And make sure your Activity extends ActionBarActivity from the compat lib
I have two menu items in menu/contacts_menu.xml as :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >
<item
android:id="#+id/pm_action_search"
android:actionViewClass="android.widget.SearchView"
android:icon="#drawable/ic_action_search"
android:orderInCategory="1"
android:showAsAction="ifRoom|collapseActionView"
android:title="#string/action_search"/>
<item
android:id="#+id/show_online"
android:icon="#drawable/online_icon"
android:orderInCategory="2"
android:showAsAction="ifRoom"
android:title="Show Online"/>
</menu>
Where , in my Fragment :
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.contacts_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.show_online) {
// DO SOMETHING
return true;
}
return super.onOptionsItemSelected(item);
}
I have done the same procedure in my others apps, and action items are showing. But in my current app, they are not showing. only if i press the menu button, action items are showing only with text. i want to show the icons on my action bar.
I guess you are using appcompat library? Try this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appcompat="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/pm_action_search"
android:actionViewClass="android.widget.SearchView"
android:icon="#drawable/ic_action_search"
android:orderInCategory="1"
android:showAsAction="always|collapseActionView"
appcompat:showAsAction="always|collapseActionView"
android:title="#string/action_search" />
<item
android:id="#+id/show_online"
android:icon="#drawable/online_icon"
android:orderInCategory="2"
android:showAsAction="always"
appcompat:showAsAction="always"
android:title="Show Online" />
</menu>
This should definitely work, but for simplicity you can also try this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:appcompat="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/pm_action_search"
android:actionViewClass="android.widget.SearchView"
android:icon="#drawable/ic_action_search"
android:orderInCategory="1"
appcompat:showAsAction="always|collapseActionView"
android:title="#string/action_search" />
<item
android:id="#+id/show_online"
android:icon="#drawable/online_icon"
android:orderInCategory="2"
appcompat:showAsAction="always"
android:title="Show Online" />
</menu>