I use navigation drawer activity in my code. For certain menu, icons are visible. But for the rest it appears as a shaded square/circle. I tried clean/rebuild/invalidate cache and restart options, still no solution. Any help please...
activity_main_drawer.xml:
<?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/fullstackdeveloper"
android:icon="#mipmap/ic_launcher_stack"
android:title="#string/home_label" />
<item
android:id="#+id/resourceperson"
android:icon="#mipmap/ic_launcher_person"
android:title="#string/about_us_label" />
<item
android:id="#+id/collegeworkshops"
android:icon="#mipmap/ic_launcher_workshop"
android:title="#string/portfolio_label" />
<item
android:id="#+id/tutorials"
android:icon="#mipmap/ic_launcher_tutorial"
android:title="#string/contacts_label" />
<item
android:id="#+id/tutorialvideos"
android:icon="#mipmap/ic_launcher_video"
android:title="#string/tutvideos_label" />
<item
android:id="#+id/scripts"
android:icon="#mipmap/ic_launcher_script"
android:title="#string/scripts_label" />
<item
android:id="#+id/androidapps"
android:icon="#mipmap/ic_launcher_android"
android:title="#string/androidapps_label" />
<item
android:id="#+id/analytics"
android:icon="#mipmap/ic_launcher_analytics"
android:title="#string/analytics_label" />
<item
android:id="#+id/python"
android:icon="#mipmap/pythonlogo"
android:title="#string/python_label" />
<item
android:id="#+id/rprogramming"
android:icon="#mipmap/rprogramming"
android:title="#string/rprogramming_label" />
<item
android:id="#+id/machinelearning"
android:icon="#mipmap/ic_launcher_machine"
android:title="#string/machinelearning_label" />
<item
android:id="#+id/booking"
android:icon="#mipmap/contacts"
android:title="#string/booking_label" />
</group>
Make sure you are following material design stander while creating icon for menu.
If you follow then it will show icons otherwise not.
You can confirm this by setting following icon
android:icon="#android:drawable/ic_menu_search"
You will see this icon in your drawer.
Above suggestion is 1 way to show icon in drawer other way is what #jeetparmar has suggest in above answer you can follow that also.
Try this way :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
android:id="#+id/Home"
app:actionLayout="#layout/home_item"
tools:ignore="MenuTitle" />
</group>
==========home_item============
<RelativeLayout
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/home"
android:layout_width="wrap_content"
android:src="#mipmap/home"
android:layout_centerVertical="true"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:text="#string/HOME"
android:textColor="#color/colorblack"
android:layout_toRightOf="#+id/home"
android:layout_marginLeft="#dimen/_8sdp"
android:layout_height="wrap_content">
</TextView>
<ImageView
android:id="#+id/right"
android:alpha="0.3"
android:layout_width="#dimen/_20sdp"
android:src="#mipmap/right_arrow"
android:layout_margin="#dimen/_8sdp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="#dimen/_4sdp"
android:layout_height="#dimen/_20sdp">
</ImageView>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#+id/right"
android:layout_marginLeft="#dimen/_22sdp"
android:background="#c0c0c0"/>
</RelativeLayout>
Related
I wanted to change the color of icons in the bottom app bar. I am using the bottom app bar for the first time so I don't have any prior knowledge of it.
The code of the XML file having bottom app bar is below
<RelativeLayout
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NavigActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorAccent">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottom_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="#color/colorAccent"
app:navigationIcon="#drawable/ic_menu_black_24dp"
app:menu="#menu/menu"
app:buttonGravity="center_vertical"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add_black_24dp"
app:layout_anchor="#id/bottom_app_bar"
android:backgroundTint="#color/colorPrimary"
app:maxImageSize="35dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/content_frame"
/>
</RelativeLayout>
The menu file used in this is below
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/home"
android:title="Home"
android:icon="#drawable/ic_home_black_24dp"
app:showAsAction="ifRoom"
/>
<item
android:id="#+id/my_invoices"
android:title="Invoices"
android:icon="#drawable/ic_receipt_black_24dp"
app:showAsAction="ifRoom"
/>
<item
android:id="#+id/notification"
android:title="Notification"
android:icon="#drawable/ic_notifications_black_24dp"
app:showAsAction="ifRoom"
/>
</menu>
I wanted the color o the icon to change to primaryColor but it is not changing..Any help would be appreciated
You can try on menu.xml
Find the detail on link. (image)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="[URL]http://schemas.android.com/apk/res/android[/URL]"
xmlns:app="[URL]http://schemas.android.com/apk/res-auto[/URL]">
<item
android:id="#+id/menu_color_change"
android:title="Color Plate"
app:showAsAction="ifRoom"
android:icon="#drawable/ic_color_plate">
</item>
<item
android:id="#+id/menu_other"
android:title="Other"
app:showAsAction="never"
android:iconTint="#android:color/white"
android:icon="#drawable/ic_color_plate">
</item>
</menu>
I have side menu in my app that contain regular menu items, but menu_button_enable_push has to look like button. Tried to use app:actionLayout, but it has no effect. Any ideas how can it be done?
menu.xml
<menu>
<item
android:id="#+id/menu_home"
android:icon="#drawable/ic_home"
android:checked="true"
android:title="Домой" />
<item
android:id="#+id/menu_settings"
android:icon="#drawable/ic_cog"
android:title="Настройки" />
<item
android:id="#+id/menu_info"
android:icon="#drawable/ic_question"
android:title="Информация" />
<item
android:id="#+id/menu_button_enable_push"
android:title="#string/button_enable_push"
app:actionLayout="#layout/menu_button"/>
</menu>
menu_button.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/activatedBackgroundIndicator"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="#fff" />
I want to set a black background with a white textview to the topmost item of the hamburger menu.It tried dynamically but setting Menu Item class does not have any propert setBackgroundDrawable etc.This is my menu and I want to set the background to navigation_item_1.pls help me
<?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">
<group android:id="#+id/grp1" android:checkableBehavior="single" >
<item
android:id="#+id/navigation_item_1"
android:checked="true"
android:icon="#drawable/ic_home"
android:title="get i5 Pro" />
</group>
<group android:checkableBehavior="single">
<item
android:id="#+id/home"
android:icon="#drawable/ic_home"
android:title="Home"/>
<item
android:id="#+id/activate_pro"
android:icon="#drawable/ic_pro"
android:title="Active PRO"/>
<item
android:id="#+id/my_music"
android:icon="#drawable/ic_music_list"
android:title="My Music"/>
<item
android:id="#+id/nav_browse"
android:icon="#drawable/ic_brows_black"
android:title="Browse and Discover" />
<item
android:id="#+id/radio_stations"
android:icon="#drawable/ic_radio_station"
android:title="Radio Stations"/>
<item
android:id="#+id/new_releases"
android:icon="#drawable/ic_new_release"
android:title="New Releases"/>
<item
android:id="#+id/my_profile"
android:icon="#drawable/ic_profile"
android:title="My Profile" />
<item
android:id="#+id/music_lang"
android:icon="#drawable/ic_checked"
android:title="Music Languages" />
<item
android:id="#+id/settings"
android:icon="#drawable/ic_settings"
android:title="Settings"/>
<item
android:id="#+id/nav_login"
android:icon="#drawable/ic_logout"
android:title="Log in " />
<item
android:id="#+id/nav_log_out"
android:icon="#drawable/ic_logout"
android:title="Log out " />
</group>
</menu>
In xml file having navigation view add following code inside navigation view as :
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal"
android:layout_marginTop="330dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_home"/>
<TextView
android:id="#+id/mSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:textColor="#ffffff"
android:text="get i5 Pro" />
</LinearLayout>
</android.support.design.widget.NavigationView>
Where you have to give margin top of linear layout according to your header height.. e.g. If your header height is 320 dp then you need to increase is by 10 dp or more according to your requirement.
This question already has answers here:
How to open sub menu after click on menu-item in Navigation drawer?
(3 answers)
Closed 7 years ago.
I am new in android and in my project I want to add the navigation drawer. I am selecting Navigation Drawer activity and create project in eclipse please help me how to develop navigation drawer below
Here is the image of navigation drawer for item and sub item menu
Use NavigationView
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header_main_navigation"
app:itemBackground="#drawable/nav_view_item_background"
app:itemTextColor="#color/nav_item_text_color"
app:menu="#menu/activity_main_navigation_drawer" />
activity_main_navigation_drawer code
<?xml version="1.0" encoding="utf-8"?>
<group android:checkableBehavior="single" android:id="#+id/root_group">
<item
android:id="#+id/item_home"
android:checked="true"
android:title="Home" />
<item android:title="You" android:id="#+id/you_parent_item">
<menu android:id="#+id/you_menu">
<group android:checkableBehavior="single" android:id="#+id/you_group">
<item
android:id="#+id/item_you_summary"
android:title="Summary Detail" />
<item
android:id="#+id/item_calendar"
android:title="Calendar" />
<item
android:id="#+id/item_request_timeout"
android:title="Request TimeOut" />
<item
android:id="#+id/item_cancel_requests"
android:title="Cancel Requests" />
<item
android:id="#+id/item_approval_responses"
android:title="Approval Responses" />
<item
android:id="#+id/item_transaction"
android:title="Transactions" />
<item
android:id="#+id/item_approval_request"
android:title="Approval Requests" />
<item
android:id="#+id/item_delegate"
android:title="Delegate" />
</group>
</menu >
</item>
<item android:title="Your People" android:id="#+id/your_parent_item">
<menu android:id="#+id/your_menu">
<group android:checkableBehavior="single" android:id="#+id/your_group">
<item
android:id="#+id/your_item_sumary"
android:title="View Summary" />
<item
android:id="#+id/item_record_timeout"
android:title="Record TimeOut" />
</group>
</menu>
</item>
<item android:title="Settings" android:id="#+id/setting_parent_item">
<menu android:id="#+id/setting_menu">
<group android:checkableBehavior="single" android:id="#+id/setting_group">
<item
android:id="#+id/item_log_out"
android:title="Log Out" />
</group>
</menu>
</item>
</group>
HeaderLayout if you want sent then
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/nav_header_height"
android:background="#color/cws_orange"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:theme="#style/Theme.AppTheme.AppBarOverlay">
<ImageView
android:id="#+id/imgAvatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#android:drawable/sym_def_app_icon" />
<TextView
android:id="#+id/txtUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:text="Android Studio"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="#+id/txtUserEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android.studio#android.com" />
Hi I am using listview which have multiple items adding dynamically..
I want to change the text color of listitem any idea
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#659EC7">
<ImageView android:id="#+id/icon" android:layout_width="72px"
android:layout_height="wrap_content"
android:layout_marginTop="5px" />
<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="5px"
android:paddingBottom="5px">
<TextView android:id="#+id/item1" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView android:id="#+id/item2" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:paddingTop="30px" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
</TwoLineListItem>
</LinearLayout>
I am using 2linelistIem
Here is the code I wrote and used:
It keeps the android style for all other states. it just overlays the transparent state with your desired color:
Layer list drawable for list view with custom background
as you can see in my question there is a minor bug with the focused state, but it is still the best solution i ever saw :D
Use this type of technique to change the color dynamically:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="#color/black" /> <!-- focused -->
<item android:state_focused="true" android:state_pressed="true" android:drawable="#color/black" /> <!-- focused and pressed-->
<item android:state_pressed="true" android:drawable="#color/green" /> <!-- pressed -->
<item android:drawable="#color/black" /> <!-- default -->
</selector>