android wear那些事--创建自定义布局
来源:互联网 发布:js window.open php 编辑:程序博客网 时间:2024/05/21 14:04
Creating Custom Layouts
为穿戴式设备创建布局和在手机上的操作一样,不过为了整体平衡和谐感你需要根据屏幕尺寸进行设计.直接使用手机上的UI,用户体验不是很好.阅读设计指导获取如何设计优秀穿戴式app的信息.
创建自定义通知
一般情况下你应该在手持设备上创建通知并自动同步到穿戴式设备上.这可以使你仅构建一次通知而展现在多种不同设备上(不仅是穿戴设备上,还有电视),从而避免多次的设计.
如果标准的通知样式(比如:NotificationCompat.BigTextStyle或者NotificationCompat.InboxStyle)不能满足你的工作需求,你可以使用自定义布局去展示.你只能在穿戴式设备上创建和展示自定义通知,系统不会同步到手持设备上.
注意:当在穿戴式设备上创建自定义通知时,你可以用标准通知的API(API 20)代替支持库.
创建自定义通知
1.为Activity的内容创建一个自定义布局视图
public void onCreate(Bundle bundle){ ... setContentView(R.layout.notification_activity);}
2.在清单文件中为Activity定义必要的属性,使其可以展示在穿戴式设备上下文中.你需要声明Activity的以下属性:exportable
,allowEmbedded
taskAFFinity
,另外推荐使用Theme.DeviceDefault.Light
主题.
<activity android:name="com.example.MyDisplayActivity" android:exported="true" android:allowEmbedded="true" android:taskAffinity="" android:theme="@android:style/Theme.DeviceDefault.Light" />
3.为希望展示的Activity创建隐式意图
Intent notificationIntent = new Intent(this, NotificationActivity.class);PendingIntent notificationPendingIntent = PendingIntent.getActivity( this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
4.建立一个Notification并调用setDisplayIntent()方法.当用户触发点击这个通知后系统就会启动这个隐式意图.
5.用notify方法展示通知.
当通知在主屏幕上展示时,系统会用标准模版展示它.当用户向上滑动这个通知时,将会看到为通知设置的自定义视图.
使用Wearable UI Library创建布局
Wearable UI Library这个库在创建可穿戴式app的时候会被自动包括.也可以在在build.gradle
中添加这个库.
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.google.android.support:wearable:+' compile 'com.google.android.gms:play-services-wearable:+'}
这个库帮助你构建UI,更多信息可以参考Creating Custom UIs for Wear Devices.下面是这个类库中一些主要的类.
- BoxInsetLayout
- CardFragment
- CircledImageView
- ConfirmationActivity
- CrossFadeDrawable
- DelayedConfirmationView
- DismissOverlayView
- GridViewPager
- GridPagerAdapter
- FragmentGridPagerAdapter
- DotsPageIndicator
- WatchViewStub
- WearableListView
- android wear那些事--创建自定义布局
- Android Wear 进阶 - 3.1 Creating Custom UIs for Wear Devices-Defining Layouts 创建自定义的手表设备UIs-定义布局
- Android Wear 进阶 2.2 Create Custom Layout 创建自定义的布局
- android wear那些事--添加语音功能
- android wear那些事--通过蓝牙调试
- android wear-创建Notification
- Android Wear 进阶 - 3 Creating Custom UIs for Wear Devices 创建自定义的手表设备UIs
- #android wear那些事--使你的应用可见
- android wear那些事--打包穿戴式应用
- AndroidWear 创建Android Wear 项目
- 使用Android Studio创建Android Wear项目
- 在Android Wear 上创建通知
- Android Wear:创建可穿戴应用 - 概述
- android wear第一个应用,创建 Notification
- Android Wear 开发-创建第一个卡片
- Android:创建可穿戴应用 - 自定义布局
- android 自定义控件那些事
- Android Wear
- 根据方法返回值来区分重载方法
- python标准库之re
- 20161102小记
- [uboot] (番外篇)global_data介绍
- 字符串、字符数组、list之间相互转化
- android wear那些事--创建自定义布局
- 关于Json解析的问题
- c语言之simp _link
- 51nod 最小集合
- OpenCV中Mat类的图像如何设置ROI
- Android简易集成二维码,条形码扫描
- 11.02
- 文件上传—DiskFileItemFactory核心类
- Resources.load的使用