如何解决Android Tiles for Wear 不清楚调试预览
我开始更新我们的磨损模块,以跟上 Google Play 的最新指南。 由于我这样做,我决定将 Tiles API 添加到应用程序。当准备好公开发布时,它将已经实施。 文件:https://developer.android.com/training/articles/wear-tiles#preview
很不清楚……有人明白吗?
wear-tiles-renderer 库提供了一种在应用内的 Activity 中预览 Tiles 的方法。 要预览您的 Tile,请创建一个使用渲染器库来渲染 Tile 的活动。将此活动添加到 src/debug 而不是 src/main,因为您将仅将此活动用于调试目的。有关示例,请参见以下代码示例:
我尝试手动将示例代码添加到调试文件夹,因为我无法从 Android Studio 添加它。
在 main 中添加了 xml 文件,也在 debug 文件夹中添加了测试。
当我加载应用程序时,它会打开我的文件夹 src/main 的主文件,但冻结了。
解决方法
文档中的引用试图解释的是您需要一个看起来像这样的模块:
您的实际磁贴及其所需的一切都在主文件夹中。然后在调试文件夹中你需要以下三样东西:
清单 - 非常标准
<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 - 这里重要的是 TileManager
class 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 中是否有任何错误消息可以帮助您了解发生了什么问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。