java - Navigation drawer item doesn't take proper paddin in the left side -


i'm using android material design drawer layout. working perfectly. i'm fetching little bit problem drawer layout item padding left in android api lever <= 19.

it works in android api level >= 21. @ screenshot :

enter image description here

but in android api level <= 19, drawer layout items don't take proper padding in left side. @ screenshot:

enter image description here

my xml files following:

activity_main.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_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitssystemwindows="true" tools:opendrawer="start" style="@style/styleactivity">  <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="300dp"     android:layout_height="match_parent"     android:layout_gravity="start"     android:fitssystemwindows="true"     app:headerlayout="@layout/nav_header_main"     app:menu="@menu/activity_main_drawer"       android:background="@drawable/graphics_drawer_bg"     app:itemtextcolor="@color/white_light"     app:itembackground="@drawable/graphics_item_bg"     app:itemicontint="@color/white_light"     />  </android.support.v4.widget.drawerlayout> 

activity_main_drawer.xml

<?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/nav_top"     android:checkablebehavior="single">     <item         android:id="@+id/nav_routine"         android:icon="@drawable/ic_access_time_accent_24dp"         android:title="routines" />     <item         android:id="@+id/nav_class"         android:icon="@drawable/ic_book_accent_24dp"         android:title="classes" />     <item         android:id="@+id/nav_exam"         android:icon="@drawable/ic_local_library_black_24dp"         android:title="exams" />     <item         android:id="@+id/nav_event"         android:icon="@drawable/ic_date_range_black_24dp"         android:title="events" />     <item         android:id="@+id/nav_statistics"         android:icon="@drawable/ic_insert_chart_black_24dp"         android:title="statistics" /> </group>  <group     android:id="@+id/nav_bottom"     android:checkablebehavior="single">     <item         android:id="@+id/nav_settings"         android:icon="@drawable/ic_settings_black_24dp"         android:title="settings" />     <item         android:id="@+id/nav_help"         android:icon="@drawable/ic_help_outline_black_24dp"         android:title="help" /> </group>  </menu> 

thanks in advance.

try adding padding in android.support.design.widget.navigationview.

for example:

<android.support.design.widget.navigationview     ...     android:padding="10dp"     ... /> 

as mentioned in comment want add padding in devices having api <= 19. this, make 2 folders in res directory.

values-v11 , values-v21

in these folders, add file dimens.xml , in add dimension navigationview.

in dimens.xml of values-v11:

<dimen name="padding_left">10dp</dimen> 

in dimens.xml of values-v21:

no padding api >= 21 <dimen name="padding_left">0dp</dimen> 

and in navigationview looks this:

<android.support.design.widget.navigationview         ...         android:paddingleft="@dimen/padding_left"         android:paddingstart="@dimen/padding_left"         ...     /> 

update:

in material design, margin , padding predefined can override these values.

<dimen name="design_navigation_padding_top_default" tools:override="true">0dp</dimen> <dimen name="design_navigation_separator_vertical_padding" tools:override="true">0dp</dimen> <dimen name="design_navigation_padding_bottom" tools:override="true">0dp</dimen> 

i found here


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -