本文出处:http://blog.youkuaiyun.com/scarthr/article/details/42194659
TV UI就是指Android系统的数字电视的图形交互界面。TV UI最大的特点就是屏幕大,为此我们要解决好以下3个问题:
1. 为大屏幕提供适当的布局源文件
2. 保证UI在一定距离仍然可以看清
3. 为高清电视提供高分辨率图标和图像
一 TV UI布局
二 TV UI导航设计
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 选择状态 -->
<item android:drawable="@drawable/tab_wy_now" android:state_selected="true"/>
<!-- 按下状态 -->
<item android:drawable="@drawable/tab_wy_now" android:state_pressed="true"/>
<!-- 取得焦点状态 -->
<item android:drawable="@drawable/tab_wy_now" android:state_focused="true"/>
<!-- 悬浮状态 -->
<item android:drawable="@drawable/tab_wy_now" android:state_hovered="true"/>
<!-- 默认状态 -->
<item android:drawable="@drawable/tab_wy"/>
</selector>
三 TV不支持的功能
相机:android.hardware.camera
导航GPS:android.hardware.location.gps
麦克风:android.hardware.microphone
近场通信(NFC):android.hardware.nfc
通话:android.hardware.telephony
触屏:android.hardware.touchscreen
这些功能通常都是TV所不支持的。
如何设置Android系统不带有触摸功能呢?
在Manifest中配置:
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
就可以安装到不支持的Android系统中。
通常电视是没有内置GPS的,如果你的程序需要用到地理位置信息,那么可以使用“static location provider”得到这些信息,这种方式是通过查询邮编完成的:
LocationManager manager = (LocationManager)
.getSystemService(Context.LOCATION_SERVICE);
Location location = manager.getLastKnownLocation("static");
查出的结果保存在location对象中。
下面是检测当前可用性的代码,来区别是手机还是TV。
if (getPackageManager().hasSystemFeature("android.hardware.telephony")) {
Log.i("Mobile Test", "该设备是手机");
} else if (getPackageManager().hasSystemFeature(
"android.hardware.touchscreen")) {
Log.i("Tablet Test", "该设备不支持通话,但是支持触屏");
} else {
Log.i("TV Test", "该设备是TV");
}