How to get a thinner font in options menu android - java

I've tried making a option menu in my activity, and I succeed. The problem now, is that the text style is bold, and I don't know how to make it normal. I tried setting textStyle, but it had no effect.
option_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/AppointmentItem"
app:showAsAction="always"
android:icon="#drawable/ic_notifications_white_24dp"
android:title="Appointments"/>
<item android:id="#+id/WeekItem"
app:showAsAction="never"
android:icon="#drawable/ic_today_24dp"
android:title="Week vooruit/achteruit"/>
<item android:id="#+id/LeerlingItem"
app:showAsAction="never"
android:icon="#drawable/ic_person_24dp"
android:title="Leerling veranderen"/>
<item android:id="#+id/InstelllingenItem"
app:showAsAction="never"
android:icon="#drawable/ic_settings_24dp"
android:title="Instellingen"/>
<item android:id="#+id/OverItem"
app:showAsAction="never"
android:icon="#drawable/ic_work_white_24dp"
android:title="Over ons"/>
</menu>
How I create the options menu in my mainactivity.java
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.option_menu, menu); //your file name
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.AppointmentItem:
return true;
case R.id.WeekItem:
getWeek();
return true;
case R.id.LeerlingItem:
getLeerling();
return true;
case R.id.InstelllingenItem:
getSettings();
return true;
case R.id.OverItem:
getAbout();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
How it looks (first) and how I want it (last):

Fixed it by changing "TextAppearance.AppCompat.Widget.ActionBar.Title" to "TextAppearance.AppCompat.Widget.ActionBar.Subtitle".
<style name="MyActionBar.MenuTextStyle" parent="style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle">
<item name="android:textColor">#color/black</item>
<item name="android:textStyle">normal</item>
<item name="android:textSize">16dp</item>
</style>
Thanks to #Rotwang for advising me to check the styles.xml

Related

Can't get Android Menu to Show

I am trying to get a 3 dot menu to show in my app but can't get it to work.
I have created a file called mymenu.xml under res/menu and the contents are:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/level"
android:title="#string/Level"
app:showAsAction="never">
</item>
</menu>
This is what is in my MainActivity.java file:
#Override
public boolean onCreateOptionsMenu(Menu my_menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mymenu, my_menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.level:
levelMax = 41;
levelTextView.setText("Level:\nEasy");
mCountDownTimer.cancel();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
What am I doing wrong? Any help would be appreciated. Thanks.
Change app:showAsAction="never" to app:showAsAction="always"

How can I implement onCreateOptionsMenu on my bottomNavigationView

Hi I wouldike to know when I click on my bottomnavigationView how to display my search toolbar ?
getMenuInflater().inflate(R.menu.toolbar_menu, menu);
return super.onCreateOptionsMenu(menu);
}
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
return true;
case R.id.navigation_loope:
toolbar_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:title="Search"
android:id="#+id/action_search"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"/>
</menu>
Bottom_nav_view.xml
<item
android:id="#+id/navigation_home"
android:icon="#drawable/ic_home"
android:title="#string/title_home" />
<item
android:id="#+id/navigation_loope"
android:icon="#drawable/ic_loope"
android:title="#string/title_loope"
/>
<item
android:id="#+id/navigation_take_photo"
android:icon="#drawable/ic_take_photo"
android:title="#string/title_take_photo" />
<item
android:id="#+id/navigation_public"
android:icon="#drawable/ic_public"
android:title="#string/title_public" />
</menu>
I can't actually use getMenuInflater().inflate(R.menu.toolbar_menu, menu) I don't know how to implement it for doing the same result when i click on my loope (R.id.navigation_loope)
EDIT : Bottom_nav_view it's for my bottom bar and toolbar_menu for my topbar. If I click on the item navigation_loop, I wouldike to show the search bar on the top.

Android Activity Menu

I wanted to create an option menu which shows up similar to Whatsapp even if the device has its own "hardware" option button. The solution I found online worked just fine until I wanted to add another action to the Bar.
Menu:
<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/addViewedMovie"
android:icon="#mipmap/ic_add_to_queue_black_24px"
android:showAsAction="always"
></item>
<item
android:title=""
android:id="#+id/menu_overflow"
android:icon="#mipmap/ic_more_vert_white_48dp"
app:showAsAction="always">
<menu>
<item
android:id="#+id/show_settings"
app:showAsAction="never"
android:title="#string/setttings"/>
<item
android:id="#+id/show_help"
app:showAsAction="never"
android:title="#string/help"/>
<item
android:id="#+id/show_about"
app:showAsAction="never"
android:title="#string/about"/>
</menu>
</item>
</menu>
And this in my MainActivity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
With this the app forces the addViewedMovie Action into an Overflow-Menu. Does anyone know how to prevent this?
Try this code and tell me if its work.. you should use app:showAsAction not android:showAsAction also you do not need to use submenu to show 3 dots.. just below code works fine also show 3 dots
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:title="Movie"
android:id="#+id/addViewedMovie"
android:icon="#mipmap/ic_add_to_queue_black_24px"
app:showAsAction="always"/>
<item
android:id="#+id/show_settings"
app:showAsAction="never"
android:title="#string/setttings"/>
<item
android:id="#+id/show_help"
app:showAsAction="never"
android:title="#string/help"/>
<item
android:id="#+id/show_about"
app:showAsAction="never"
android:title="#string/about"/>
</menu>
Create a folder name Menu in your res folder.
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/search"
android:icon="#drawable/ic_launcher"
myapp:showAsAction="ifRoom" />
<item android:id="#+id/abc"
android:title="ABC" />
<item android:id="#+id/abc1"
android:title="ABC1" />
<item android:id="#+id/abc2"
android:title="ABC2" />
</menu>
In java file put this:-
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.search:
return true;
case R.id.abc:
return true;
case R.id.abc1:
return true;
case R.id.abc2;
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Simple.
use app instead of android as app is for design support library.
And so, in Gradle build in dependencies, you must have: compile com.android.support:design..... like that. But, I have seen that you already used it below. So,
Just use: app:showAsAction="never" instead of android:showAsAction="always" in your addViewedMovie item.
Remember: never means it will be on overflow menu item. always means is will show in action bar.
If you are using in a fragment, add below line in the onCreate
setHasOptionsMenu(true);
And two more functions
#Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
}
Inflate your views in the above method. Listen to the action in the below one.
#Override public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

Action items/icons not displaying on action bar in Android App

I am trying to have a search action on my action bar. I have set an icon and have showAsAction set to always but it is still always displayed in the overflow menu. How can I make it display on the action bar itself? Thanks!
Activity
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
setTitle("Add");
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
Toast.makeText(getApplicationContext(), "Settings",
Toast.LENGTH_LONG).show();
return true;
}
if (id == R.id.action_search) {
Toast.makeText(getApplicationContext(), "Search",
Toast.LENGTH_LONG).show();
return true;
}
return super.onOptionsItemSelected(item);
}
}
Menu XML file
<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.testtabs.MainActivity" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never"/>
<item
android:id="#+id/action_search"
android:actionViewClass="android.support.v7.widget.SearchView"
android:icon="#drawable/ic_search"
android:showAsAction="always"
android:title="#string/title_search"/>
</menu>
Either remove
android:actionViewClass="android.support.v7.widget.SearchView"
or delete your case statement for action_search in onOptionsItemSelected. Doing either of those will display the icon.
If you want to use SearchView the callback is handled differently than onOptionsItemSelected.
Documentation here: http://developer.android.com/guide/topics/ui/actionbar.html#ActionView
Just change app:showAsAction instead of android:showAsAction
<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.testtabs.MainActivity" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"`enter code here`
android:title="#string/action_settings"
app:showAsAction="never"/>
<item
android:id="#+id/action_search"
android:actionViewClass="android.support.v7.widget.SearchView"
android:icon="#drawable/ic_search"
app:showAsAction="always"
android:title="#string/title_search"/>
</menu>

Android Menus and Sub-Menus

I'm having trouble creating a radio-button sub-menu that is shown when a menu item from the options menu that appears when a user presses the menu button is selected. This is what I have so far:
// Expand the options menu when the user taps their menu button
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch item.getItemId() {
case R.id.expandRadioMenu:
// Show the sub-menu and collapse the initial menu
return true;
}
}
The XML of res/menu/menu.xml is as follows:
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:visible="true"
android:enabled="true"
android:checkable="false"
android:icon="#drawable/ic_menu_mark"
android:id="#+id/expandRadioMenu"
android:title="Select"
android:titleCondensed="select">
<menu>
<group
android:enabled="true"
android:visible="false"
android:checkableBehavior="single"
android:id="#+id/radio">
<item
android:enabled="true"
android:visible="true"
android:title="Foo"
android:titleCondensed="Foo"
android:id="#+id/foo">
</item>
<item
android:enabled="true"
android:visible="true"
android:title="Bar"
android:titleCondensed="Bar"
android:id="#+id/bar">
</item>
</group>
</menu>
</item>
</menu>
I know it's not particularly appealing, but have you tried moving the sub menu into a separate .xml file? I've seen it work before, but it's not a terribly hopeful solution. I suppose it might further identify the problem though.

Categories

Resources