i want to change the position of items of toolbar but im not found gravity
i hava menu_main.xml
<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="haythamayyash.myapplication.MainActivity">
<item
android:id="#+id/action_settings"
android:orderInCategory="2"
android:title="#string/action_settings"
app:showAsAction="never"/>
<item
android:id="#+id/backbutton"
android:orderInCategory="1"
android:title="back"
android:icon="#drawable/ic_action_name"
app:showAsAction="ifRoom"
/>
</menu>
and i have 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="haythamayyash.myapplication.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
the items appear on the right side on the toolbar by default,
how can i change the position of items from right to left ?
app:showAsAction="never"
This will make the option hidden. It will be shown only when you click on the menu icon(3 dots on right top of the screen) or menu button of the phone.
app:showAsAction="always"
This will display the option always at the navigation bar.
android:orderInCategory="1"
This will decide the position/order of the option
Related
This question already has answers here:
NavigationView get/find header layout
(9 answers)
Closed 1 year ago.
I have done my best to reproduce a UI design for an android navigation drawer.
I have already designed the nav header to look like what is in the UI design.
When I run the app, the header (the layout in nav_header_home.xml) is not visible in the simulator.
The nav_header_home.xml for the navigationdrawer:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/clientPrimaryBlue"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
app:srcCompat="#drawable/home" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:text="Home"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
</LinearLayout>
activity_home_drawer.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<item android:title="Movies">
<menu>
<item
android:id="#+id/nav_action"
android:icon="#drawable/ic_menu_share"
android:title="Action" />
<item
android:id="#+id/nav_adventure"
android:icon="#drawable/ic_menu_send"
android:title="Adventure" />
<item
android:id="#+id/nav_comedy"
android:icon="#drawable/ic_menu_send"
android:title="Comedy" />
<item
android:id="#+id/nav_crime"
android:icon="#drawable/ic_menu_send"
android:title="Crime" />
<item
android:id="#+id/nav_drama"
android:icon="#drawable/ic_menu_send"
android:title="Drama" />
<item
android:id="#+id/nav_fantasy"
android:icon="#drawable/ic_menu_send"
android:title="Fantasy" />
</menu>
</item>
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_actors"
android:icon="#drawable/ic_menu_camera"
android:title="Actors" />
<item
android:id="#+id/nav_directors"
android:icon="#drawable/ic_menu_gallery"
android:title="Directors" />
<item
android:id="#+id/nav_producers"
android:icon="#drawable/ic_menu_slideshow"
android:title="Producers" />
</group>
<item android:title="My Account">
<menu>
<item
android:id="#+id/nav_update_profile"
android:icon="#drawable/ic_menu_share"
android:title="Update Profile" />
<item
android:id="#+id/nav_reset_password"
android:icon="#drawable/ic_menu_send"
android:title="Reset Password" />
<item
android:id="#+id/nav_sign_out"
android:icon="#drawable/ic_menu_send"
android:title="Sign Out" />
</menu>
</item>
</menu>
Screenshot of expected menu layout
Screenshot of layout in android emulator
app_bar_home.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="media.client.clientmediaandroid.activity.home.HomeActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_home" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
action_home.xml with the DrawerLayout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_home"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<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_home"
app:menu="#menu/activity_home_drawer" />
</android.support.v4.widget.DrawerLayout>
With help from #MikeM., I was able to adjust my layout settings in a way that allowed me to see the navigation header.
His contribution can be read directly here -
Home Navigation header of NavigationDrawer not showing in simulator
Set the fitsSystemWindows attributes to false on the DrawerLayout and NavigationView as suggested by Mike. M.
I want to remove the shadow from these imagebuttons in my toolbar, but I can't seem to do it. I've tried setting the elevation, borderless style, and setting stateListAnimator as null. (These were suggestions on other posts.)
EDIT: Find the updated XML below. I have tried about every single suggestion in order to remove the shadows. (Even combined almost all of them) But I still can't get rid of them.
Main Layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.tqamobile.partyme.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay">
<LinearLayout
android:layout_width="wrap_content"
android:background="#00aaaaaa"
android:layout_gravity="right"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/notification_button"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:elevation="0dp"
android:background="#android:color/transparent"
android:stateListAnimator="#null"
android:theme="#style/AppTheme.ToolbarButton"
android:src="#drawable/ic_no_notifications_action" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<include
layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:itemTextColor="#color/colorAccent"
app:headerLayout="#layout/nav_header"
app:menu="#menu/menu_navigation" />
</android.support.v4.widget.DrawerLayout>
Styles
<style name="AppTheme.ToolbarButton" parent="#style/Widget.AppCompat.Button.Borderless"/>
Change background of buttons from your current attributes to #null like this:
android:background="#null"
You should add your buttons as menu items instead.
Full guide here: https://stackoverflow.com/a/31477092/4974603
<?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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".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:orderInCategory="200"
android:title="Search"
android:icon="#drawable/ic_search"
app:showAsAction="ifRoom"
></item>
<item
android:id="#+id/action_user"
android:orderInCategory="300"
android:title="User"
android:icon="#drawable/ic_user"
app:showAsAction="ifRoom"></item>
</menu>
I am facing strange problem with SearchView in toolbar.
I want to use CoordinatorLayout for my layout, so recently I have changed my root layout from LinearLayout to CoordinatorLayout. Everything is fine except the behavior of SearchView I am using is in Toolbar is strange after clicking search icon.
With LinearLayout
With CoordinatorLayout
XML Code:
<?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:id="#+id/coordinatorlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar_for_home_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/appcolor">
<ProgressBar
android:id="#+id/toolbar_progress_bar"
style="#style/AppTheme"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="right"
android:indeterminateTint="#color/white"
android:indeterminateTintMode="src_in"
android:visibility="gone" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tablayout_for_home_ativity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/appcolor"
app:tabBackground="?attr/selectableItemBackground"
app:tabGravity="fill"
app:tabIndicatorColor="#color/white"
app:tabMaxWidth="0dp"
app:tabMode="fixed"
app:tabSelectedTextColor="#color/white"
app:tabTextColor="#color/lightblue" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager_for_home_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/floatingbutton_for_home_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/activity_horizontal_margin"
android:src="#drawable/ic_person_add_white_24dp"
app:backgroundTint="#color/appcolor"
app:fabSize="normal"
app:layout_behavior="com.ficean.android.ficean.ScrollingFABBehavior" />
</android.support.design.widget.CoordinatorLayout>
In the above code if I change Coordinator layout to LinearLayout SearchView is showing up fine. If I use Coordinator layout searchicon and edittext are disappearing. But keypad is getting opened and I can still search. Problem is search icon and edit text is not showing up.
Menu Code:
<?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="Search"
android:id="#+id/search_on_activity_toolbar"
android:orderInCategory="100"
android:icon="#drawable/ic_search_white_24dp"
app:showAsAction="collapseActionView|always"
app:actionViewClass="android.support.v7.widget.SearchView"
/>
</menu>
I have a serious doubt. how can i add the expandable list button on the right end of the navigation drawer menu item in the android studio? for further details let me post my image...
I have just edited my post...
below is my 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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="#+id/view">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
android:background="#color/red"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.design.widget.TabLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/tabLayout"
android:background="#color/red"
app:tabIndicatorColor="#color/white"
app:tabTextAppearance="#style/MyStyle"
android:layout_below="#+id/toolbar"
android:scrollbars="horizontal"
android:layout_alignParentLeft="true">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/viewPager">
</android.support.v4.view.ViewPager>
</android.support.design.widget.CoordinatorLayout>
and here is my activity_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.goserwizz.NavigationActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_container">
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:headerLayout="#layout/header"
app:menu="#menu/menu_navigation"/>
</android.support.v4.widget.DrawerLayout>
And here is my menu_navigation.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/Book_my_services"
android:title="Book my services"
android:icon="#drawable/book_my_service"/>
<item
android:id="#+id/My_services"
android:title="My services"
android:childIndicatorRight="30dp"
android:icon="#drawable/services" />
<item
android:id="#+id/Add_your_vehicles"
android:title="Add your vehicles"
android:icon="#drawable/add_vehicle"/>
<item
android:id="#+id/Reschedule_slot"
android:title="Reschedule slot"
android:icon="#drawable/slot" />
<item
android:id="#+id/Cancel_services"
android:title="Cancel services"
android:icon="#drawable/cancel_service"/>
<item
android:id="#+id/history"
android:title="History"
android:icon="#drawable/history"/>
<item
android:id="#+id/Payment"
android:title="Payment"
android:icon="#drawable/payment"/>
</group>
<item android:title="HELP">
<menu>
<item
android:id="#+id/Emergency_assistant"
android:title="Emergency Assistant"
android:icon="#drawable/emergency" />
<item
android:id="#+id/Call_support"
android:title="Call support"
android:icon="#drawable/call_support" />
<item
android:id="#+id/Settings"
android:title="Settings"
android:icon="#drawable/settings" />
</menu>
</item>
<item android:title="MORE">
<menu>
<item
android:id="#+id/feedback"
android:title="Feedback"
android:icon="#drawable/feedback" />
<item
android:id="#+id/How_it_works"
android:title="How it works"
android:icon="#drawable/how_it_work"/>
<item
android:id="#+id/FAQ"
android:title="FAQ"
android:icon="#drawable/faq"/>
<item
android:id="#+id/terms_and_conditions"
android:title="Terms and conditions"
android:icon="#drawable/terms_condition"/>
<item
android:id="#+id/Privacy_policy"
android:title="Privacy policy"
android:icon="#drawable/privacy"/>
<item
android:id="#+id/About"
android:title="About"
android:icon="#drawable/about"/>
</menu>
</item>
</menu>
Now,where should i make the changes so, that i can get the expandable list button on the right side of navigation menu item.
Currently my navigation drawer looks similar to this
But i need my navigation drawer like this
I need expandable list button on the right side of navigation menu item. Kindly help me ...Many thanks in advance.....
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="#+id/navigation_drawer"
android:name="com.rooftap.adapterClass.NavigationDrawerFragment"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:layout="#layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
Customize your fragment_navigation_drawer.xml layout add spinners or whatever you want like how we do in normal layout and create a NavigationDrawerFragment.class for actions. don't use android.support.design.widget.NavigationView.
The menu items are rendered without any margin/padding.
How can I center the Menu item in the toolbar. I am using the theme Theme.AppCompat.NoActionBar.
menu_main.xml
<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=".ParkingOffendersActivity">
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="collapseActionView" />
</menu>
activity_parking_offenders.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/parking_offenders_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ParkingOffendersActivity"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/parking_offenders_toolbar"
android:minHeight="20dp"
android:background="#color/color_primary"
android:layout_width="match_parent"
android:layout_height="48dp">
</android.support.v7.widget.Toolbar>
</LinearLayout>