Android:contentDescription 不是無用


在寫Android的XML布局文件時,在ImageView或ImageButton中經常會碰到一個提示: Missing contentDescription attribute on image.

在Android 的圖片顯示類的控件中,不寫   android:contentDescription 往往會有警告(Eclipse開發時),這個屬性是方便一些生理功能有缺陷的人使用應用程序的,比如一些視力有障礙的用戶,如果用戶安裝了輔助瀏覽工具比如TalkBack,TalkBack就會大聲朗讀出用戶目前正在瀏覽的內容。TextView控件TalkBack可以直接讀出里面的內容(contentDescription的值),告訴用戶這個圖片到底是什么。


TalkBack的使用:

android:contentDescription 這個屬性必須在用戶的Accessible 中的相應屬性開啟后才能使用。

1. 首先下載google的應用 TalkBack (an accessibility service published by Google) 並且將功能打開 Settings > Accessibility > TalkBack 設置為On。

2.在應用中添加這個屬性。

<Button  
    android:id=”@+id/pause_button”  
    android:src=”@drawable/pause”  
    android:contentDescription=”@string/pause”/> 

3.用戶點擊這個控件。android系統會自動使用人聲朗讀控件上android:contentDescription屬性說指向的內容。

這個屬性的主要功能就是為視力有障礙的人增加對控件的解釋。

 

當然不想使用這個屬性時,

android:contentDescription="@null"

即可!

同樣

android:background="@null"

可以去除imagebutton丑陋的背景

 

 

 

參考:http://blog.csdn.net/yuxiaohui78/article/details/41206179


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM