Android use namespace as prefix for attributes in library

戏子无情 提交于 2019-12-01 21:04:53

问题


I am trying to implement the ActionBar through the support library, v7. Because I want to support the app for Android 2.1 (API level 7) and above.

I read in http://developer.android.com/guide/topics/ui/actionbar.html following: "Using XML attributes from the support library Notice that the showAsAction attribute above uses a custom namespace defined in the tag. This is necessary when using any XML attributes defined by the support library, because these attributes do not exist in the Android framework on older devices. So you must use your own namespace as a prefix for all attributes defined by the support library."

My question is how do I use my own namespace as a prefix for all attributes defined by the support library?

Step by step explanation please! //Thanks.


回答1:


Here is an example of a menu:

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:whatever="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@id/wims_ab_done"
        android:icon="@drawable/white_check_mark"
        android:title="@string/save"
        whatever:showAsAction="always"/>
    <item
        android:id="@id/wims_ab_items_remove"
        android:icon="@drawable/wims_remove"        
        android:title="@string/remove"
        whatever:showAsAction="always"/>

</menu>

The whole philosophy is to have http://schemas.android.com/apk/res-auto in the namespace attribute in root menu. It doesn't matter what is the namespace identifier as long as it's valid and is used as such when using showAsAction attributes. Does this answer your question?



来源:https://stackoverflow.com/questions/18514305/android-use-namespace-as-prefix-for-attributes-in-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!