0

I'd like to apply the android.support.design.widget.NavigationView divider to another view I have. I want it to be the same divider. The divider in the NavigationView for those who dont know gets created when you specify a group. You can see an example of the divider here. I want to have a view that does something like this else where:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="the same divider as navigationView"
    android:showDividers="beginning"/>

the gradle dependency for the material design package is (if it matters):

compile 'com.android.support:design:22.2.1'

so I'm just trying to reuse the same divider icon that the design library is using somewhere else.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
j2emanue
  • 60,549
  • 65
  • 286
  • 456
  • You could just make a drawable that matches the color of the divider. Then between your views just add the plain View element with the background of your custom drawable. – Max McKinney Oct 07 '15 at 18:39
  • but what if material design changes its divider ? – j2emanue Oct 07 '15 at 18:39
  • You'd have to update your gradle dependencies so you'd have time to quickly change the color of the drawable. The sizing of the View XML element can be pulled from either some default android values or custom values in your dimen.xml – Max McKinney Oct 07 '15 at 18:41
  • is there no way to pull from the library itself ? it is a aar file. Also maybe a theme or style can i pull from ? – j2emanue Oct 07 '15 at 18:42
  • Not in the way you are probably wanting. LinearLayout doesn't have a built in divider function so you'd need to make your own implementation. But someone on SO pulled the source for the divider so you could get the color and stuff from them - http://stackoverflow.com/questions/24618829/how-to-add-dividers-and-spaces-between-items-in-recyclerview – Max McKinney Oct 07 '15 at 18:44

1 Answers1

0

I looked in the design library itself and found that they are making the divider the standard way:

 <View android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="?android:attr/listDivider"/>

I copied this into my code and now im using the same divider. I didn't realize it was a standard.

you can also manipulate a linearlayout directly with setting a divider like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:showDividers="beginning"
    android:divider="?android:attr/listDivider">
lopez.mikhael
  • 9,943
  • 19
  • 67
  • 110
j2emanue
  • 60,549
  • 65
  • 286
  • 456