Not able to see icons in side navigation bar in android studio - java

I'm not able to see the icons I am providing in the menu item to see it inside the navigation bar.
Below is the code of the menu main_menu.xml file:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/home_nav" android:title="Home" android:icon="#drawable/home"/>
<item android:id="#+id/profile" android:title="Profile" android:icon="#drawable/profile"/>
<item android:id="#+id/generate_mpin" android:title="Generate Mpin" android:icon="#drawable/gen_mpin_icon"/>
<item android:id="#+id/history" android:title="My History" android:icon="#drawable/history_icon"/>
<item android:id="#+id/acc_statement" android:title="Account Statement" android:icon="#drawable/acc_stat_icon"/>
<item android:id="#+id/funds" android:title="Funds" android:icon="#drawable/funds_icon"/>
<item android:id="#+id/game_rates" android:title="Game Rates" android:icon="#drawable/game_rates_icon"/>
<item android:id="#+id/how_to_play" android:title="How To Play" android:icon="#drawable/how_to_play_icon"/>
<item android:id="#+id/settings" android:title="Settings" android:icon="#drawable/settings_icon"/>
<item android:id="#+id/logout" android:title="Logout" android:icon="#drawable/logout_icon"/>
</menu>
Below is the result I'm getting while using the above XML file:
What I getting:
What I expecting:

Related

Default font family not changing in android app

I am tried to change my font on entire app with Style.xml and it should change font everywhere on my app but i am getting same old font everywhere, only i see changes on dialog title not other places. Check the screenshot of app only no.2 screen dialog has changes. Can you please help me out. I am not able to get what wrong i am doing here.
Style.xml
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorPrimary">#color/primary</item>
<item name="colorAccent">#color/accent</item>
<item name="colorSurface">#color/white</item>
<item name="android:textColorPrimary">#color/primary_text</item>
<item name="android:textColorSecondary">#color/secondary_text</item>
<item name="android:divider">#color/divider</item>
<item name="windowActionBarOverlay">true</item>
<item name="fontFamily">#font/myfont</item>
<item name="android:fontFamily">#font/font_elaxer</item>
<item name="selectableItemBackground">?android:selectableItemBackground</item>
<item name="android:colorControlHighlight" tools:targetApi="lollipop">#color/ripplecolor</item>
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
<item name="android:textColorHint">#color/custom_hint_color</item>
<!-- enable window content transitions -->
<item name="android:windowActivityTransitions" tools:targetApi="lollipop">true</item>
<!-- specify enter and exit transitions -->
<item name="android:windowEnterTransition" tools:targetApi="lollipop">#transition/explode</item>
<item name="android:windowExitTransition" tools:targetApi="lollipop">#transition/explode</item>
<!--<item name="android:windowEnterTransition" tools:targetApi="lollipop">#android:transition/slide_right</item>
<item name="android:windowExitTransition" tools:targetApi="lollipop">#android:transition/slide_left</item>-->
<!-- specify shared element transitions -->
<item name="android:windowSharedElementEnterTransition" tools:targetApi="lollipop">#transition/change_image_transform</item>
<item name="android:windowSharedElementExitTransition" tools:targetApi="lollipop"> #transition/change_image_transform</item>
</style>
myfont.xml
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<font
app:fontStyle="normal"
app:fontWeight="400"
app:font="#font/dancing_r" />
<font
app:fontStyle="italic"
app:fontWeight="400"
app:font="#font/dancing_b" />
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="#font/dancing_r" />
<font
android:fontStyle="italic"
android:fontWeight="400"
android:font="#font/dancing_b" />
</font-family>

How to change menu title programmatically in Android

Here is my menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/home"
android:icon="#drawable/home"
android:title="#string/bottom_basic_home" />
<item
android:id="#+id/mancust"
android:icon="#drawable/ic_contacts1"
android:title="#string/customers" />
<item
android:id="#+id/catalog"
android:icon="#drawable/catalog"
android:title="#string/catalog" />
</group>
<item android:title="About"> //my changes want to appear for this item
<menu>
<group android:checkableBehavior="single">
<item
android:id="#+id/help"
android:icon="#drawable/ic_help_outline_black_24dp"
android:title="#string/help"
/>
<item
android:id="#+id/codex_logout"
android:icon="#drawable/logout"
android:title="#string/logout" />
</group>
</menu>
</item>
</menu>
I am implementing navigation drawer in my Android application. How do I set a menu group item title programmatically?
You can add id tag to your item in xml and find that item in the menu programmatically and set a new title.
Menu XML:
<item
android:id="#+id/about_title"
android:title="About">
Java/Kotlin:
val navView: NavigationView = findViewById(R.id.nav_view)
val aboutTitle = navView.menu.findItem(R.id.about_title)
aboutTitle.title = "New Title"

Why do you use onPrepareOptionsMenu to create a menu where the layout file appears at the top of the screen but the runtime appears at the bottom?

I want to make a menu on my app's top like which showed me in the AS's xml, but in Android 6.0,it's on the bottom. How can I solve this problem? Thanks.
I have tried many methods like change my code, add the android:showAsAction='always', but it doesn't work.
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_new_folder"
android:title="#string/menu_create_folder" />
<item
android:id="#+id/menu_export_text"
android:title="#string/menu_export_text"/>
<item
android:id="#+id/menu_sync"
android:title="#string/menu_sync"/>
<item
android:id="#+id/menu_setting"
android:title="#string/menu_setting" />
<item
android:id="#+id/menu_search"
android:title="#string/menu_search"/>
Create menu like this -
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/action_more"
android:orderInCategory="1"
android:icon="#drawable/ic_menu_dots"
android:title="more"
app:showAsAction="always">
<menu>
<item
android:id="#+id/menu_new_folder"
android:title="#string/menu_create_folder" />
<item
android:id="#+id/menu_export_text"
android:title="#string/menu_export_text"/>
<item
android:id="#+id/menu_sync"
android:title="#string/menu_sync"/>
<item
android:id="#+id/menu_setting"
android:title="#string/menu_setting" />
<item
android:id="#+id/menu_search"
android:title="#string/menu_search"/>
</menu>
</item>
</menu>
And in your activity's onCreateOptionMenu add this -
menu.findItem(R.id.action_more).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)

Bottom Navigation Bar not showing icons

I am initializing all of the icons with images but none of them are visible?
< ?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/nav_item1"
android:icon="#drawable/insta"
app:showAsAction="ifRoom|withText"
android:title="#string/nav1"/>
<item
android:id="#+id/nav_item2"
android:icon="#drawable/artistsample"
app:showAsAction="ifRoom|withText"
android:title="#string/nav2"/>
<item
android:id="#+id/nav_item3"
android:icon="#drawable/artistsample"
app:showAsAction="ifRoom|withText"
android:title="#string/nav3"/>
<item
android:id="#+id/nav_item4"
android:icon="#drawable/artistsample"
app:showAsAction="ifRoom|withText"
android:title="#string/nav4"/>
</menu>
Can you please use the bellow code and see what happens.
<item
android:id="#+id/nav_item2"
android:icon="#drawable/artistsample"
android:title="#string/nav2"/>
and enable app:labelVisibilityMode="labeled" in BottomNavigationView

Create a menu xml like chorme

I want to create menu xml like chorme. How can i do this?
I tried this but doesn't show any icon :(
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/action_more"
android:icon="#drawable/ic_home_black_24dp"
android:orderInCategory="100"
android:showAsAction="never"
android:title="More apps"/>
<item
android:id="#+id/action_rate"
android:icon="#drawable/ic_home_black_24dp"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Rate this app"/>
</menu>

Categories