I can not change a menu to lowercase letters - android

Problem: I can not change a menu to lowercase letters.
I have a menu as indicated below:
<?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/actionOrdenesMenuPedido"
android:orderInCategory="1"
android:title="#string/item_ordenes"
android:scaleType="fitStart"
android:icon="#mipmap/ic_carrito"
app:showAsAction="always"/>
<item
android:id="#+id/tituloMenuPedido"
android:orderInCategory="2"
android:title="#string/item_orden"
android:textAllCaps="false"
android:textAppearance="?android:attr/textAppearanceLarge"
android:enabled="false"
app:showAsAction="always"/>
<item
android:id="#+id/actionGuardarMenuPedido"
android:orderInCategory="3"
android:title="#string/item_guardar"
android:icon="#mipmap/ic_guardar"
app:showAsAction="always"/>
<item
android:id="#+id/actionCancelarMenuPedido"
android:orderInCategory="4"
android:title="#string/btn_cancelar"
android:icon="#mipmap/ic_eliminar"
android:scaleType="fitEnd"
app:showAsAction="always"/>
</menu>
And it is invoked in the following way:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_pedido, menu);
return true;
}
And the only item that displays text keeps the letters in uppercase even though they are disabled. (android:textAllCaps="false").
Any idea how to fix this?

Try this :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Holo">
<item name="android:actionMenuTextAppearance">#style/MyMenuTextAppearance</item>
</style>
<style name="MyMenuTextAppearance" parent="android:TextAppearance.Holo.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
</resources>
Hope it helps !

Related

How do I get two menu options with dropdowns next to each other in an Android layout file?

I'm trying to get a menu layout where I have 2 icons next to each other which both have dropdown options. Currently it's being annoying and putting all the items in the default option menu like this:
image
<?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="#string/menu_sort"
android:id="#+id/menu_sort"
app:showAsAction="always"
android:icon="#drawable/ic_baseline_sort_24">
<item android:title="Distance"/>
<item android:title="Salary"/>
<item android:title="Date Posted"/>
</item>
<item
android:title="#string/menu_filter"
android:id="#+id/menu_filter"
app:showAsAction="always"
android:icon="#drawable/ic_baseline_filter_list_24">
<item android:title="Freelance"/>
<item android:title="Zero Hour"/>
<item android:title="Part Term"/>
<item android:title="Internship"/>
</item>
</menu>
Maybe this can help....
<?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="#string/menu_sort"
android:id="#+id/menu_sort"
app:showAsAction="always"
android:icon="#drawable/ic_baseline_sort_24">
<menu>
<item android:title="Distance"/>
<item android:title="Salary"/>
<item android:title="Date Posted"/>
</menu>
</item>
<item
android:title="#string/menu_filter"
android:id="#+id/menu_filter"
app:showAsAction="always"
android:icon="#drawable/ic_baseline_filter_list_24">
<menu>
<item android:title="Freelance"/>
<item android:title="Zero Hour"/>
<item android:title="Part Term"/>
<item android:title="Internship"/>
</menu>
</item>
</menu>
You add <menu></menu> inside an item and add submenu items there....

Styling toolbar menu item title

I am trying to achieve the Menu Item design as shown in the YouTube application screen below. The menu item I am interested in is the action menu item. In this case the (G)
Currently, my application Looks like the image below:
My style and Background xml are as follows:
<resources>
// The themes are structured as follows :
// Theme 1 (One) : Application Theme
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/color_accent</item>
<item name="otpViewStyle">#style/OtpWidget.OtpView</item>
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="actionMenuTextColor">#color/white</item>
<item name="android:actionMenuTextColor">#color/white</item>
<item name="actionMenuTextAppearance">#style/home_menu_style</item>
<item name="android:actionMenuTextAppearance" >#style/home_menu_style</item>
</style>
// Theme 2 (two) : Splash Screen Theme
<style name="SplashScreenTheme" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
// Theme 3 (three) : No ActionBar Theme
<style name="AppTheme.NoActionbar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
// Theme 4 (four) : AppBarOverlay and PopupOverlay
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Light" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />
// Menu Style
<style name="home_menu_style" parent="AppTheme">
<item name="android:textSize">22sp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#drawable/menu_drawable</item>
<item name="android:backgroundTint">#drawable/menu_drawable</item>
<item name="backgroundTint">#drawable/menu_drawable</item>
</style>
</resources>
The menu_drawable is as follows:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#48b3ff">
</solid>
</shape>
The home_menu.xml menu item is as follows:
<?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/menu_name"
android:actionLayout="#layout/custom_layout"
android:title=""
app:showAsAction="always" />
<item
android:id="#+id/action_search"
android:icon="#drawable/sharp_search_white_24"
android:title="Search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="collapseActionView|always" />
</menu>
Code to inflate the menu:
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater)
{
super.onCreateOptionsMenu(menu, inflater)
menu.clear()
this.menu = menu
inflater.inflate(R.menu.home_menu, menu)
}
My code to change the menu item title is as follows:
var menu: Menu
menu.findItem(R.id.menu_name).setTitle(name)
The menu preview looks as follows:
Firstly, you need to create a custom_menu.xml 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/profile"
<!-- this is the magic !!! -->
android:actionLayout="#layout/custom_layout"
android:icon="#drawable/ic_action_profile"
android:title="#string/profile_update"
app:showAsAction="always" />
</menu>
After this, you create a layout file custom_layout.xml like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="#dimen/margin_extra_small"
android:background="#drawable/drawable_circle_solid_accent"
android:gravity="center"
android:padding="#dimen/padding_small"
android:text="G"
android:textColor="#color/colorWhite"
android:textSize="#dimen/text_size_normal"
android:textStyle="bold" />
</LinearLayout>
and set this custom_menu.xml in your activity.
Output:
Add this in your activity:
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
// getting action layout menu item
val menuItemName = menu?.findItem(R.id.menu_name)
// getting Linear Layout from custom layout
val linearLayout = menuItemName?.actionView as LinearLayout
// getting TextView from Linear Layout, i.e., parent of custom layout
val yourTextView = linearLayout.findViewById<TextView>(R.id.your_text_view_id)
// setting the first char of the String name
yourTextView.text = name.substring(0, 1)
return super.onPrepareOptionsMenu(menu)
}

How to distribute the items of a menu equally?

I have a menu as follows:
<?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"
android:layout_gravity="center">
<item
android:id="#+id/actionOrdenesMenuPedido"
android:orderInCategory="1"
android:title="#string/item_ordenes"
android:scaleType="fitStart"
android:icon="#mipmap/ic_carrito"
app:showAsAction="always"/>
<item
android:id="#+id/tituloMenuPedido"
android:orderInCategory="2"
android:title="#string/item_orden"
android:textAllCaps="false"
android:textAppearance="?android:attr/textAppearanceLarge"
android:enabled="false"
app:showAsAction="always"/>
<item
android:id="#+id/actionGuardarMenuPedido"
android:orderInCategory="3"
android:title="#string/item_guardar"
android:icon="#mipmap/ic_guardar"
app:showAsAction="always"/>
<item
android:id="#+id/actionCancelarMenuPedido"
android:orderInCategory="4"
android:title="#string/btn_cancelar"
android:icon="#mipmap/ic_eliminar"
android:scaleType="fitEnd"
app:showAsAction="always"/>
</menu>
I have retired the title as follows:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and when the application works it looks like this:
My question is: Is there a way that the items are not on the left, that is, distributed evenly across the width?
Thanks in advance

How to change color of menu in actionbar?

I want change background of menu and set it to blue. Now background of my menu is black.How to change this?
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.nabege.AboutUsActivity" >
<item
android:id="#+id/help"
android:title="#string/help" />
<item
android:id="#+id/setting"
android:title="#string/setting"/>
Java codes :
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.about_us, menu);
return super.onCreateOptionsMenu(menu);
}
Put the following styles in your styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/primary_color</item>
<!--<item name="colorPrimaryDark">#color/primary_color</item>-->
<item name="colorAccent">#color/primary_color</item>
<item name="actionBarStyle">#style/AppThemeActionBarStyle</item>
</style>
<style name="AppThemeActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="background">#color/your_background_color</item>
</style>
Hope this helps.

Android actionbar only show overflow

my actionbar is only showing the items in overflow. the androidstudio displays the items correct in the actionbar (not overflow). if i run the app on emulator or on my device the items always appears in overflow
action_bar.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_home"
android:icon="#drawable/ic_home"
app:showAsAction="always|withText"
android:title="home"/>
<item
android:id="#+id/action_share"
android:title="share"
android:icon="#android:drawable/ic_menu_share"
app:showAsAction="always"
/>
themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="#android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/MyAppTheme.ActionBarStyle</item>
</style>
<style name="MyAppTheme.ActionBarStyle" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyAppTheme.ActionBar.TitleTextStyle</item>
<item name="android:displayOptions">showHome</item>
</style>
<style name="MyAppTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#000000</item>
</style>
</resources>
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_bar, menu);
return super.onCreateOptionsMenu(menu);
}
thanks for any help....
You are using Theme.Holo. This means that you are trying to use the native action bar. In that case, change app:showAsAction to android:showAsAction.
The following code would solve your problem.
<item
android:id="#+id/action_share"
android:icon="#android:drawable/ic_menu_share"
android:showAsAction="always"
android:title="share"/>
Note the namespace used for the attributes.

Categories

Resources