Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation Drawer Android API specific Layout Attribute

Hello I have created a navigation drawer with ListView navigation using ActionBar Sherlock and android support Library v4 for old version compatbility (my app's minSdkversion="8") in which I have used some attributes for textview in ListView:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:gravity="center_vertical"
    android:paddingLeft="16dp"
    android:paddingRight="5dp"
    android:textColor="#fff"
    android:background="?android:attr/activatedBackgroundIndicator"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"/>

This is showing error as ?android:attr/activatedBackgroundIndicator is from API 11 and ?android:attr/textAppearanceListItemSmall & ?android:attr/listPreferredItemHeightSmall are from API 14.

I managed to support ?android:attr/activatedBackgroundIndicator by replacing it with actionBar Sherlock's ?attr/activatedBackgroundIndicator. But I didn't find any equivalence for other two attributes. There is ?attr/textAppearanceListItemSmall in actionBar Sherlock but it is not properly working.

So what are the equivalence for these attributes to provide support all the API above 2.1 ?

like image 285
Kaidul Avatar asked Jul 13 '13 11:07

Kaidul


People also ask

How do I change my navigation drawer to open from right to left?

set DrawerLayout tools:openDrawer="end" set NavigationView android:layout_gravity="end" change tag view from androidx.


2 Answers

To support lower versions, instead of removing the following three parameters,

  android:textAppearance="?android:attr/textAppearanceListItemSmall" 
  android:background="?android:attr/activatedBackgroundIndicator"
  android:minHeight="?android:attr/listPreferredItemHeightSmall"

You can actually replace them with equivalent values/resources.

The equivalent values can be obtained from https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml

Now,

  • a) android:textAppearance="@android:style/TextAppearance.Medium"

  • b)

    1. Download a selector from https://github.com/habzy/Test0011_DialerPad/blob/master/res/drawable/list_item_activated_background.xml

    2. In the above project browse the resources in hdpi,mdpi etc and get files named list_activated_holo.9.png

    3. Finally

    android:background="@drawable/list_item_activated_background"

  • c) From the equivalent values obtained , we know that listPreferredItemHeightSmall is 48dip

    android:minHeight="48dip"

like image 97
yajnesh Avatar answered Nov 15 '22 17:11

yajnesh


I am not sure if you really need to use android dimensions (like listPreferredItemHeightSmall etc.) In some android version can that dimension be 12 and in other 14. I suggest you to create your own dimension, which will be used in your whole app, and you can easily edit them when change is needed.

like image 28
Koso Avatar answered Nov 15 '22 17:11

Koso