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>
Related
I have created Slide menu with navigation drawer, action bar hidden on main activity, items are not clickable and navigation item images not visible correctly. attaching images and code below.
This is how it looks
How it should be(in iOS)
navigation added in main_activity.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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawer_layout"
android:fitsSystemWindows="true"
android:background="?attr/colorButtonNormal"
tools:context=".MainActivity"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:id="#+id/toolbar"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:elevation="4dp"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragment_container"/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="#+id/nav_view"
app:headerLayout="#layout/nav_header"
app:itemTextColor="#color/viewBgr"
app:menu="#menu/drawer_menu"
/>
nav_header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:background="#color/statusBar"
android:gravity="bottom"
android:padding="16dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
android:layout_height="100dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABC"
android:textColor="#color/viewBgr"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
/>
</LinearLayout>
drawer_menu.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"
>
<group android:checkableBehavior="single">
<item android:id="#+id/nav_nightmode"
android:icon="#drawable/theme"
android:title="Theme"/>
<item android:id="#+id/nav_touch"
android:icon="#drawable/fingerprint"
android:title="Touch Id"/>
</group>
<item android:title="Cmmunicate">
<menu>
<item android:id="#+id/nav_contact"
android:icon="#drawable/contact_us"
android:title="Contact Us"/>
<item android:id="#+id/nav_notification"
android:icon="#drawable/notification"
android:title="Notification"/>
<item android:id="#+id/nav_userguide"
android:icon="#drawable/user_guide"
android:title="User Guide"/>
<item android:id="#+id/logout"
android:icon="#drawable/logout"
android:title="Logout"/>
</menu>
</item>
</menu>
created another styles.xml with v24 api and added to the Android Manifest file with no action bar to the particular activity
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
</resources>
MainActivity.java
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setBackgroundColor(getResources().getColor(R.color.navigation));
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
action added in the same class find the below method
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem)
Try this :
<?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">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="true"
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="#color/white"
app:popupTheme="#style/AppTheme.PopupOverlay">
.....
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">
<include
layout="#layout/app_bar_dashboard" // APP_BAR
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"
app:headerLayout="#layout/nav_header_dashboard"
app:itemIconTint="#drawable/drawer_item"
app:itemTextColor="#drawable/drawer_item"
app:menu="#menu/activity_dashboard_drawer" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
According to this xml you have to changes in java class also.
If this will not work please let me know in comment.
EDIT:
app_bar_dashboard:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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="ai.gramboard.app.activity.DashboardActivity">
<include layout="#layout/content_dashboard"/> //include here content xml
</FrameLayout>
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 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.
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
I implement ExpandableListView but i have also items in menu xml, so how can i declare that this list view should be below of one of the item inside of my menu.xml? For example if i want expandablelistview below location item what should i do? Here is my code:
menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item android:id="#+id/location" android:icon="#drawable/mylocation" android:title="#string/My_Location" android:animateLayoutChanges="true"/>
</group>
<item android:title="#string/action_settings">
<menu>
<group android:checkableBehavior="single">
<item android:id="#+id/profile" android:icon="#drawable/settings"
android:title="#string/Edit_Profile" android:animateLayoutChanges="true" />
<item android:id="#+id/logout" android:icon="#drawable/logout"
android:title="#string/Log_Out" android:animateLayoutChanges="true"/>
</group>
</menu>
</item>
</menu>
And drawer_main.xml
<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/layout"
android:layout_width="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true" tools:openDrawer="start">
<include layout="#layout/app_bar_main" 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="left|start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer"
android:nestedScrollingEnabled="true"
app:itemIconTint="#FFFFFF"
app:itemTextColor="#FFFFFF"
android:background="#000000">
<FrameLayout
android:id="#+id/drawer_list_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ExpandableListView
android:id="#+id/navList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
So my problem is that the ExpandableListView remain top and i dont want to use layout_marginTop because it depends on user screen. Is there any other way to accomplish this issue?