Usage of ?android:attr/ in backwards compatible apps

五迷三道 提交于 2019-11-28 23:28:05
pawelzieba

As is in the documentation some styles are in higher API. For example:

  • dividerVertical since API 11
  • dividerHorizontal since API 11

? mark is used to reference style in current theme.

To deal with your problem you can:

  • use styles from API 11, but put them to values-v11 folder and support styles for older versions in values using custom values or different attributes from older API.
  • copy necessary styles from ICS
  • don't use these styles
  • use custom styles

It depends what's your aim. First suggestion makes sense when native style of application is important for you.
If you want to have Holo style everywhere then there is no way than copy it and use as a one style for all platforms.
Take a look at this project: https://github.com/Prototik/HoloEverywhere

to use styles from API 11 Specifically android:attr/textAppearanceMedium ?android:attr/dividerVertical ?android:attr/dividerHorizontal

The easiest way is to use following code where ever your required

<!-- For Horizontal Line-->
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:background="#aaa"
android:layout_alignParentTop="true"/>

<!-- For Vertical Line-->

<View
android:id="@+id/VerticalLine"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip"
android:layout_marginTop="4dip"
android:background="#aaa"/>

Please check android support v7 - appcompat project. It has many themes and attributes for backwards compatibility (attr/dividerHorizontal also)

http://developer.android.com/tools/support-library/features.html#v7-appcompat

To use v7 support you must import it as an Android lib project and reference to it from you project. It also contains v4 support so you may want to remove v4 support in your libs folder :) Good luck!!

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