How to adjust space between Icon and Title in NavigationView? - android

How to adjust this ? I am trying to make a navigation drawer in my app,I managed to add horizontal lines between items, but I want to adjust space between the icon and the title.

The best approach is to use a RecyclerView inside NavigationDrawer. You can always customize a recyclerView item (i.e. providing gaps between different elements).

another way to implement this,,
use navigation bar like this
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
app:headerLayout="#layout/drawer_header"
android:background="#00fdfdfd"
app:itemIconTint="#android:color/white"
app:itemTextColor="#android:color/white">
<LinearLayout
android:animateLayoutChanges="true"
android:layout_marginTop="45dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/pull_navBar"
android:layout_width="35dp"
android:layout_height="match_parent">
<ImageView
android:layout_marginTop="105dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_double_arrow_left"/>
</LinearLayout>
<LinearLayout
android:background="#color/grey"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:padding="2dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2">
<TextView
android:textColor="#android:color/holo_blue_light"
android:text="Date"
android:textSize="16dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:textColor="#android:color/holo_blue_light"
android:text="Session Name"
android:layout_weight="1"
android:textSize="16dp"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rec_sessionList"
android:layout_width="match_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</LinearLayout>
</android.support.design.widget.NavigationView>
you can put any root layout inside the navigation and achive any view

Add this code in style.xml
<style name="NavStyle" parent="Base.TextAppearance.AppCompat">
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/candidate_title</item>
<item name="android:padding">0dip</item>
</style>
and set app:itemIconPadding="#dimen/activity_margin_10dp"
app:itemTextAppearance="#style/NavStyle"in NavigationView

Related

Layout design over navigation action bar

I am looking for a solution to design an element on the top of the navigation action bar and also a way to increase the size of the action bar. One way I can think of, is to disable the navigation action bar and then design. Is there any way if it's achievable without disabling the action bar?
Here is the design template:
just to be clear i am looking for an idea to design connect tab where one half is on the navigation action bar while other is on scroll view
xml for main
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:background="#696969">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:background="#696969">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Filter"
android:layout_marginLeft="20dp"
android:textSize="26sp"
android:textColor="#color/white"
>
</Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="scan"
android:textSize="26sp"
android:layout_marginLeft="20dp"
android:textColor="#color/white"
>
</Button>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
here is xml for toolbar
<?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="wrap_content"
android:layout_gravity="center"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/backkground">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="10dp"
app:cardElevation="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:background="#color/black">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:padding="2dp"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:src="#drawable/ic_baseline_cast_connected_24">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:text="Connected"
android:textSize="44sp">
</TextView>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
I am afraid i can show all the codes as its proprietry but i just wrote some to mitigate my current solution by dividing the background colo.lol.
After hard work of 30min. I got your answer. In your image, Toolbar is already in use with backButton, refreshButton, BluetothButton, and locationButton and they created the Connect button in TabLayout that's why it shows half on TabLayout and half on Blank Spaces.
I created it as shown in the template.
This is my XML layout code.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Your ToolBar Code or Other Code-->
<TableLayout
android:id="#+id/myTooBar"
android:layout_width="match_parent"
android:layout_gravity="top"
android:layout_height="?actionBarSize">
<!-- Here is sample textView with color-->
<TextView
android:background="#color/purple_500"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</TableLayout>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:gravity="center"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
app:cardCornerRadius="15dp"
app:cardElevation="10dp"
app:layout_anchor="#+id/myTooBar"
app:layout_anchorGravity="bottom|center"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:background="#color/white"
android:padding="15dp"
android:gravity="left"
android:text="#string/connect"
android:textColor="#color/gray"
android:textSize="22sp"
android:textStyle="bold"
app:drawableLeftCompat="#drawable/ic_baseline_cell_wifi_24"
app:drawableTint="#color/gray" />
</androidx.cardview.widget.CardView>
<!-- Your more code of Activity-->
</androidx.coordinatorlayout.widget.CoordinatorLayout>
and this is the result
I hope it'll help you.
EDIT -1: Added more radius to cardView

Adding a button to footer of navigation drawer list android

I have a navigation drawer made using drawer layout and adapter. I want to add a logout button at the bottom of the side menu. I went through SO, but couldn't solve. The main xml file has a list view in a drawer layout.
<?xml version="1.0" encoding="utf-8"?>
<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">
<LinearLayout 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:orientation="vertical"
android:weightSum="5"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:layout_gravity="center"
android:orientation="vertical">
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/buttonbackground"
android:text="PHOTOS"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textColor="#color/white" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/buttonbackground"
android:text="VIDEOS"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textColor="#color/white" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/buttonbackground"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:text="HISTORY"
android:textColor="#color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5"></LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/navList"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_above="#+id/logout"
android:layout_gravity="left|start"
android:background="#ffeeeeee"></ListView>
<Button
android:id="#+id/logout"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="LogOut" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
<android.support.v4.widget.DrawerLayout/>
And the list is being inflated in the java code.
private void addDrawerItems() {
String items[]={"Home","Video","Camera","History","Version"};
mAdapter=new ArrayAdapter<>(this,R.layout.listview_drawer_item_row,items);
mDrawerList.setAdapter(mAdapter);
}
How do I add a button at the bottom of the menu?
Can you try this, Its a work around but I hope it'll give some idea to solve your issue
<android.support.v4.widget.DrawerLayout android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left|start">
<ListView
android:id="#+id/navList"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_above="#+id/logout"
android:layout_gravity="left|start"
android:background="#ffeeeeee"></ListView>
<Button
android:id="#+id/logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="LogOut" />
</RelativeLayout>
As per my experience and knowledge you need to add your logout button as footerview of your listview or either set it to bottom in your navigation view. You can't place your button outside of your navigationView. If you manage to achieve something like that you will be only able to scroll your navigation view not your logout button. I assume it won't scroll with your navigationView.
For this to achieve, make a custom layout as per your requirement and set as a footerview or either set it in bottom of your navigationView.

Android set full width on custom layouts for menu

I'm trying to attach custom layout for menu items on DrawerLayout, but as you see menu items don't have full width and i can't resolve this problem
My menu layout
<?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/groupOne">
<item
android:id="#+id/inbox"
app:actionLayout="#layout/create_new"/>
</group>
</menu>
and my custom layout for that as create_new
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<TextView
android:layout_width="match_parent"
android:layout_height="25dp"
android:text="New Text"
android:gravity="left|center"
android:layout_marginLeft="20dp"
android:background="#000"
android:textColor="#fff"/>
</LinearLayout>
Yeah, the only way that worked for me was to set android:layout_width="100000dp" on the custom layout's root view.
Ugly ugly hack, however.
Add custom Spinner in Navigation menu / Navigation drawer / menu item.
1) Create Menu Item in menu directory.
<menu>
> <item
> android:id="#+id/navigation_drawer_item3"
> app:actionLayout="#layout/nav_drawer_home_spinner"
> tools:ignore="MenuTitle,icon" />
</menu>
2)Navigation drawer where you can put all types of navigation drawer
here.
- header
-menu with icon
-menu without icon
-custom menu item (Spineer)
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#color/md_white_1000"
tools:openDrawer="start">
<include
layout="#layout/app_bar_dashboard"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/navigation_drawer_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="0dp"
android:background="#color/md_white_1000"
android:nestedScrollingEnabled="true"
android:layout_gravity="start">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="vertical"
android:background="#color/md_white_1000">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/md_white_1000">
<android.support.design.widget.NavigationView
android:id="#+id/navigation_drawer_with_icon"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center"
android:elevation="0dp"
android:background="#color/md_white_1000"
app:itemTextColor="#color/colorAccent"
app:itemIconTint="#color/colorAccent"
app:headerLayout="#layout/nav_header_dashboard"
android:theme="#style/NavigationViewStyle"
app:menu="#menu/activity_dashboard_drawer"/>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_drawer_without_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/md_white_1000"
app:itemTextColor="#color/colorAccent"
android:elevation="0dp"
android:layout_gravity="bottom"
android:theme="#style/NavigationViewStyleOnlyText"
app:menu="#menu/activity_dashboard_withouticon_drawer"/>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_drawer_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
android:layout_gravity="bottom"
app:menu="#menu/activity_dashboard_spinner"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
3) Custom row_spinner_layout for putting your custom layout for menu
item of that navigation view.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:orientation="horizontal">
<ImageView
android:id="#+id/img_profilPic"
android:layout_width="0dp"
android:layout_weight="0.15"
android:layout_height="wrap_content"
android:padding="3dp"
android:src="#drawable/profilepic" />
     
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.7"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:orientation="vertical">
<TextView
android:id="#+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#color/colorAccent"
android:text=""/>
<TextView
android:id="#+id/tv_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#color/colorAccent"
android:text=""/>
</LinearLayout>
</LinearLayout>

Lollipop Drawer Fragment appears behind bottom bar

In my app my navigation drawer layout is as follows:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/nav_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ccc"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:orientation="vertical"
tools:context=".NavigationDrawerFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/blue"
android:orientation="vertical"
android:paddingEnd="#dimen/drawer_padding"
android:paddingLeft="#dimen/drawer_padding"
android:paddingRight="#dimen/drawer_padding"
android:paddingStart="#dimen/drawer_padding">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="50dp"
android:paddingTop="5dp"
android:src="#drawable/menu_logo" />
<TextView
android:id="#+id/drawer_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:textColor="#android:color/white" />
</LinearLayout>
<View
android:id="#+id/divider"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_below="#+id/header"
android:background="#color/yellow" />
<LinearLayout
android:id="#+id/bottom_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="50dp"
android:layout_alignParentBottom="true"
android:background="#color/white"
android:orientation="vertical"
android:paddingEnd="#dimen/drawer_padding"
android:paddingLeft="#dimen/drawer_padding"
android:paddingRight="#dimen/drawer_padding"
android:paddingStart="#dimen/drawer_padding">
<LinearLayout
android:id="#+id/drawer_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/drawer_item_padding"
android:paddingTop="#dimen/drawer_item_padding">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="#drawable/ic_drawer_settings" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="10"
android:paddingLeft="#dimen/drawer_padding"
android:text="#string/drawer_settings"
android:textSize="#dimen/menu_item_text" />
</LinearLayout>
<LinearLayout
android:id="#+id/drawer_logout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="#dimen/drawer_item_padding"
android:paddingTop="#dimen/drawer_item_padding">
...
</LinearLayout>
</LinearLayout>
<ScrollView
android:background="#color/white"
android:id="#+id/scroller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom_options"
android:layout_below="#+id/divider"
android:paddingEnd="#dimen/drawer_padding"
android:paddingLeft="#dimen/drawer_padding"
android:paddingRight="#dimen/drawer_padding"
android:paddingStart="#dimen/drawer_padding"
android:scrollbarStyle="outsideOverlay">
<LinearLayout
android:id="#+id/main_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
...
</LinearLayout>
</ScrollView>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
However in Lollipop the drawer seems to be "underneath" the bottom bar buttons. In Kitkat (image to the right) it works fine (there should be padding there):
What I have tried:
Adding <item name="android:fitsSystemWindows">true</item> to the App Theme
The only "answer" here does not work: In Android 5.0 listview tuple overlaps bottom bar
So I had to add this to a styles-v21:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Which made the views align but turned my status bar bright blue. So I added a style for each activity (v21):
<style name="activityStyle">
<item name="android:paddingTop">25sp</item> <!-- so that it's under the status bar -->
<item name="android:background">#color/colorPrimaryDark</item>
</style>

Center title on ToolBar

I have a problem, I can't center my title in my Toolbar (#+id/toolbar_title). I tried to put a RelativeLayout, use layout_gravity: center but it doesn't work. I have added colors to distinguish the layout but I can't post pictures yet.
http://hpics.li/72b1cf7
activity_main.xml
<android.support.v4.widget.DrawerLayout
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:context=".MainActivity"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#android:color/holo_green_dark"
app:theme="#style/ToolbarTheme"
app:popupTheme="#style/Theme.AppCompat"
android:layout_gravity="center_vertical"
>
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:background="#color/primaryDark"
android:textSize="20dp"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/primary">
<ImageButton
android:id="#+id/show_list_actualites"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_fleche_bas"
android:adjustViewBounds="true"
android:layout_toLeftOf="#+id/loupe"
android:layout_marginLeft="20dp"
android:layout_marginRight="15dp"
android:layout_centerVertical="true"
android:padding="15dp"
android:background="#color/primaryDark"
/>
<!--android:background="#android:color/transparent"-->
<ImageView
android:id="#+id/loupe"
android:layout_width="wrap_content"
android:layout_height="12dip"
android:src="#drawable/ic_rech"
android:rotation="270"
android:adjustViewBounds="true"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:background="#color/primaryDark"
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</RelativeLayout>
<RelativeLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/content_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="#+id/slide_news_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone">
<ListView
android:id="#+id/list_slider_news_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/action_bar_background"
android:text="Item 1"/>
<Button
android:id="#+id/close_news_slide"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey_tranparent"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<ListView
android:id="#+id/left_drawer"
android:background="#android:color/white"
android:layout_width="305dp"
android:layout_height="match_parent"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.AppCompat.Light.NoActionBar" parent="#style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDark</item>
</style>
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="ToolbarTheme" parent="Theme.AppCompat">
<item name="android:windowNoTitle">true</item>
<item name="android:textColorPrimary">#color/action_bar_text</item>
<item name="actionMenuTextColor">#color/action_bar_text</item>
<item name="android:textColorSecondary">#color/action_bar_text</item>
<item name="android:layout_gravity">center_horizontal</item>
</style>
</resources>
Centering the Text in the Toolbar is against Android design standards. I think this is why you are having issues accomplishing this. I would not try to adjust your text alignment, which will insure your app fits within the Android ecosystem.
Check this link for details on Toolbar design standards: http://www.google.com/design/spec/layout/structure.html#structure-toolbars
I am not answering how you WOULD do what you are asking, but suggesting that you DON'T do it in the first place (use the standard format, and this will be easier for you).
try this code...
Toolbar's parent is viewgroup. So u cannot design like that. I used FrameLayout to place items.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/primary">
<ImageButton
android:id="#+id/show_list_actualites"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:adjustViewBounds="true"
android:layout_toLeftOf="#+id/loupe"
android:layout_marginLeft="20dp"
android:layout_marginRight="15dp"
android:layout_centerVertical="true"
android:padding="15dp"
android:background="#color/primaryDark"
/>
<!-- android:background="#android:color/transparent"-->
<ImageView
android:id="#+id/loupe"
android:layout_width="wrap_content"
android:layout_height="12dip"
android:src="#drawable/ic_launcher"
android:rotation="270"
android:adjustViewBounds="true"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:background="#color/primaryDark"
/>
</RelativeLayout>
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:background="#color/primaryDark"
android:textSize="20dp"
android:text="Title"
/>
</FrameLayout>

Categories

Resources