okay, Google Keeps-Notes and Lists App have a navigation drawer like this,
Google Keeps-Notes and Lists App Navigation Drawer(Original)
I want to do same exact as I mention in this image. I want this
'EDIT'
I want that EDIT (the TextView) at right side of navigation drawer.
I achieved this far,My Navigation Drawer
<group>
<item android:title="LABALS"
android:actionLayout="#layout/main_nav_drawer_edit">
<menu>
<item
android:id="#+id/navigation_drawer_lable"
android:title="Label 1" />
<item
android:id="#+id/navigation_drawer_create_new_label"
android:title="Create new label" />
</menu>
</item>
what should I do to achieve this, Is it possible?
Create a custom View and apply to the app:actionLayout attribute of your <item>.
<item
android:id="#+id/grp_labeled"
android:title="LABALS"
app:actionLayout="#layout/main_nav_drawer_edit">
<menu>
<item
android:id="#+id/navigation_drawer_lable"
android:title="Label 1" />
<item
android:id="#+id/navigation_drawer_create_new_label"
android:title="Create new label" />
</menu>
</item>
layout:
<androidx.constraintlayout.widget.ConstraintLayout 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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EDIT"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
like this?
Related
I have the menu item that consists of 5 items which are Home, Property, Help, Users & Account. My question is, how should I do to make the Help menu looks like the picture below. Can someone help me?
Here is my xml code for menu
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="#+id/nav_home"
android:icon="#drawable/bottom_menu_home_s"
android:title="Home" />
<item
android:id="#+id/nav_property"
android:icon="#drawable/bottom_menu_property_s"
android:title="Property" />
<item
android:id="#+id/nav_panic"
android:icon="#drawable/bottom_menu_panic"
android:title="Help" />
<item
android:id="#+id/nav_user"
android:icon="#drawable/bottom_menu_users_s"
android:title="Users" />
<item
android:id="#+id/nav_account"
android:icon="#drawable/bottom_menu_accounts_s"
android:title="Account" />
Try this, as you can not do directly
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
app:itemIconTint="#color/colorPrimary"
app:itemTextColor="#android:color/black"
app:menu="#menu/bottom_navigation"
android:clipChildren="false"
android:layout_height="56dp">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/help_button"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
app:elevation="6dp"
android:scaleType="center"/>
</com.google.android.material.bottomnavigation.BottomNavigationView>
You have to download/create customized icon first. Menu doesn't allow customization like a drawable.
I am trying to put active/inactive drawables for bottomnavigationview menu items. Going through several post in SO and browsing in Google I could find only setting colour for active/inactive state using app:itembackgroundColor what I want to achieve is set drawable when selected.
I tried this for menuitems
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_home"
android:icon="#drawable/home_navigation_view_home_selector"
android:checked="false"
android:title="#string/title_home" />
<item
android:id="#+id/navigation_dashboard"
android:icon="#drawable/home_navigation_view_oppurtunity_selector"
android:checked="false"
android:title="#string/title_oppurtunity" />
<item
android:id="#+id/navigation_notifications"
android:icon="#drawable/home_navigation_view_leads_selector"
android:checked="false"
android:title="#string/title_leads" />
<item
android:id="#+id/navigation_settings"
android:icon="#drawable/home_navigation_view_settings_selector"
android:checked="false"
android:title="#string/title_settings" />
</menu>
where
home_navigation_view_home_selector/
home_navigation_view_oppurtunity_selector/
home_navigation_view_leads_selector/
home_navigation_view_settings_selector
are selector for each item.
home_navigation_view_home_selector.xml
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_home_selected"
android:state_checked="true" />
<item android:drawable="#drawable/ic_home_black_24dp" />
</selector>
the bottomnavigationview code is as follows
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
android:foreground="?attr/selectableItemBackground"
app:menu="#menu/navigation" />
but doesn't seem to work.
Any help will be appreciated.
Try:
navigation.setItemIconTintList(null);
in your code.
Bottom Navigation View uses color tinting by default, so you have to disable it.
I want to add a menu item entry without icon to navigation drawer in my android app.
I have checked the samples at NavigationDrawer
and read through the tutorial at Android Developer training article.
I edited the sample menu to add new menu items "My Text 1" and "My Text 2" as per this xml file following this image:
<?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/nav_camera"
android:icon="#drawable/ic_menu_camera"
android:title="Import" />
<item
android:id="#+id/nav_gallery"
android:icon="#drawable/ic_menu_gallery"
android:title="Gallery" />
<item
android:id="#+id/nav_slideshow"
android:icon="#drawable/ic_menu_slideshow"
android:title="Slideshow" />
<item
android:id="#+id/nav_manage"
android:icon="#drawable/ic_menu_manage"
android:title="Tools" />
<item
android:id="#+id/example"
android:title="My Text 1" />
</group>
<item android:title="Communicate">
<menu>
<item
android:id="#+id/nav_share"
android:icon="#drawable/ic_menu_share"
android:title="Share" />
<item
android:id="#+id/nav_send"
android:icon="#drawable/ic_menu_send"
android:title="Send" />
<item
android:id="#+id/sample"
android:title="My Text 2" />
</menu>
</item>
</menu>
If i remove the two lines declaring icons for "Share" and "Send", then "My Text 2" gets aligned to the left as shown in this image
But i want to keep the icons of other items, and just add a text item, i hope there is some parameter that allows no icon menu item in groups.
I tried using android_icon="#android/color:transparent", but that doesn't/can't solve the problem either.
I dont want to provide any icons for my menu items, but i expect that text to align to the left. Is that achievable? If yes, how?
No custom layout here.
You have to create a second group with an ID (even dummy) then in this group put all the items without any icon.
Note: every time the group ID changes Android adds a separator line.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_home"
android:icon="#drawable/ic_menu_dummy1"
android:title="#string/nav_menu_home"/>
<item
android:id="#+id/nav_profile"
android:icon="#drawable/ic_menu_dummy2"
android:title="#string/nav_menu_profile"/>
</group>
<group android:id="#+id/dummy">
<item
android:id="#+id/nav_info"
android:title="#string/nav_menu_info"/>
<item
android:id="#+id/nav_settings"
android:title="#string/nav_menu_settings"/>
</group>
Create your custom layout for the Navigation Drawer and do whatever you want with that:
This is my xml file for custom design of drawer layout-
<?xml version="1.0" encoding="utf-8"?>
<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=".HomeActivity">
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/rl_topbar"
layout="#layout/inflate_topbar" />
<FrameLayout
android:id="#+id/fl_content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/rl_topbar" />
</LinearLayout>
<!-- The navigation drawer -->
<LinearLayout
android:id="#+id/ll_navbar_container"
android:layout_width="#dimen/navbar_width"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="#color/color_255_255_255"
android:orientation="vertical">
<!--This is my custom layout how I want, you can design as you want and include it-->
<include
android:id="#+id/ll_navbar"
layout="#layout/inflate_navbar" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
<!--Add progress bar-->
<!--Add other views-->
</RelativeLayout>
Now in your activity of this xml file take the references of views and make click events or other changes easily.
A simple alternative would be to use a custom layout instead of a menu.
It'll be a simple change. Simply, you can just create a custom layout as you would in any other layout but instead of indicating the corresponding menu within the NavigationView, instead of using the app:menu="#menu/drawer_view" attribute.
You can simply follow the layout structure of in your Activity.
<android.support.design.widget.CoordinatorLayout
<android.support.v4.widget.DrawerLayout
<RelativeLayout/>
<LinearLayout/>
</android.support.v4.widget.DrawerLayout>
</android.support.design.widget.CoordinatorLayout>
There's no fundamental difference between the structure of the tutorial and that of this layout except, I've chosen to use a LinearLayout instead of a menu resource for the side menu (obviously the rootlayout for the side view will be at your discretion but for your use-case LinearLayout fits best.).
An Example
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/colorAccent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true">
<include layout="#layout/content_activity_main"/>
<include layout="#layout/layout_side_view"/>
</android.support.v4.widget.DrawerLayout>
</android.support.design.widget.CoordinatorLayout>
You'll notice in this layout that there are two include statements in place of the layouts before as shown in the structure before. One for the actual content of the activity and one for the side view. I'll show you an example of your requested use case layout below:
layout_side_view.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="50dp">
<TextView
android:id="#+id/with_icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#color/black"
android:drawableLeft="#drawable/icon"
android:drawableStart="#drawable/icon"
android:drawablePadding="15dp"
android:gravity="start|center_vertical"
android:text="TextView 1"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="50dp">
<TextView
android:id="#+id/without_icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#color/black"
android:gravity="start|center_vertical"
android:text="Text View 2"/>
</LinearLayout>
</LinearLayout>
You can then simply customize your layout and where you want a TextView with an icon on the left use the DrawableLeft | DrawableStart attribute, and if you don't want an icon simply just don't use it.
I hope this helps.
Note:
I would look into what the DrawerLayout does and why it is structured that way, the content goes below the menu for what reason? Looking into these things helps you develop an understanding where you can customize layout structures to your liking.
I have simple requirement to display some text in the actionBar near the menu. How can I acheive it?
What it looks like now?
What I need?
Try this ActionBar menu sample:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourApp="http://schemas.android.com/apk/res-auto"
>
... ...
<item
android:id="#+id/item_text"
yourApp:showAsAction="always"
yourApp:actionLayout="#layout/action_text"
/>
</menu>
Then you need a layout action_text for your TextView:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
>
... ...
<TextView android:id="#+id/lb_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/your_text"
android:textSize="10sp"
android:textColor="#color/white"
/>
</RelativeLayout>
Hope this help!
<item
android:id="#+id/action_refresh"
android:icon="#android:drawable/ic_input_add"
android:title="Options"
app:showAsAction="withText|always" />
<item
android:id="#+id/action_options_unused"
app:showAsAction="withText|always"
android:title="Options"
/>
Don't set a android:icon if you don't want an icon appearing at the left side of your textual item. Also make sure this <item> is the last one in your menu's XML file.
I want to reproduce this tab indicator structure (screen is from nova launcher): a dropdown menu and an arrow in the right bottom corner.
I have no problem about code but i can't reproduce this appearance.
I tried this:
mBar.addTab(mBar.newTab().setText(ctx.getString(R.string.tab_actions)).setTabListener(this).setCustomView(R.layout.navigation_spinner));
where mBar is sherlock support actionBar.
This is my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_margin="-10dp"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<Button android:id="#+id/button1" android:layout_width="match_parent"
android:layout_height="match_parent" android:text="Button" />
</LinearLayout>
and this is my result:
The problem is that the button in the central tab doesn't fill the tab indicator. How can i set a custom view that perfectly fill the indicator without margin or padding? Or i have to approach this in a different way to have the a result like the firs screen? Thanks in advice
What you are trying to do is really complicated, and will be hard to achieve.
If you want drop down menus you can try those :
menu/options.xml:
<item
android:icon="#drawable/ic_menu_sort"
android:showAsAction="ifRoom">
<menu>
<item
android:id="#+id/menuSortNewest"
android:title="Sort by newest" />
<item
android:id="#+id/menuSortRating"
android:title="Sort by rating" />
</menu>
</item>
Second option:
menu/options.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menuSort"
android:showAsAction="ifRoom"
android:actionLayout="#layout/action_sort" />
</menu>
layout/action_sort.xml:
<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_menu_refresh"
android:entries="#array/order" />
Docs for menu resources - http://developer.android.com/guide/topics/resources/menu-resource.html