我开始更新我们的穿戴模块,使其与 Google Play 的最新指南保持同步。
因为我这样做了,所以我决定将 Tiles API 添加到应用程序中。当准备好公开发布时,它将已经实现。
文件:https://developer.android.com/training/articles/wear-tiles#preview
很不清楚......有人明白吗?
wear-tiles-renderer 库提供了一种在应用内的 Activity 中预览 Tiles 的方法。
要预览您的 Tile,请创建一个使用渲染器库来渲染 Tile 的 Activity 。在 src/debug 而不是 src/main 中添加此 Activity ,因为您将仅将此 Activity 用于调试目的。有关示例,请参见以下代码示例:
我尝试手动将示例代码添加到调试文件夹,因为我无法从 Android Studio 添加它。
在 main 中添加了 xml 文件,并在 debug 文件夹中添加了进行测试。
当我加载应用程序时,它会打开我的文件夹 src/main 的主文件,但会卡住。
如果在调试中,我是否需要添加任何代码来加载示例?
最佳答案
文档中的引用试图解释的是您需要一个看起来像这样的模块:
您的实际磁贴及其所需的一切都放在主文件夹中。然后在调试文件夹中,您需要以下三样东西:
list - 相当标准
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tiles">
<uses-feature android:name="android.hardware.type.watch" />
<application
android:label="@string/tiles_app_name">
<activity
android:name=".MainActivity"
android:label="@string/tiles_app_name"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity - 这里重要的是 TileManagerclass MainActivity : ComponentActivity() {
private lateinit var tileManager: TileManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.tile_test)
val rootLayout = findViewById<FrameLayout>(R.id.tile_container)
tileManager = TileManager(
context = this,
component = ComponentName(this, SampleTile::class.java),
parentView = rootLayout
)
tileManager.create()
}
override fun onDestroy() {
super.onDestroy()
tileManager.close()
}
}
布局 - 也很标准<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tile_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
如果你已经完成了所有这些设置并且它仍然卡住,那么你的 Tile 类中可能有一个错误。查看 Logcat 中是否有任何错误消息可以帮助您了解问题所在。
关于Android Tiles for wear 不清晰调试预览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67334133/