android - 查找 R 的引用名称的值

标签 android android-layout android-xml

我正在我的应用程序中进行一些调试,主要是在我的自定义 View 被赋予 style="@styles/CustomStyle" 等属性时从 styles.xml 加载自定义样式custom:attribute="自定义值"

我查看了 TextView 源代码以了解 Android 如何加载样式/属性,并且我正在模仿它。但是,我没有通过对我的构造函数的一些调用传递我的任何 R.styleables,所以我试图在那里查看哪些资源正在进入。

我正在使用 obtainStyledAttributes() 将这些键/值对加载到 TypedArray 中,但是我想知道是否有一种简单的方法来转换 R.styleable.CustomWidget_customAttributeR 读取的 int 到它的引用名称。

本质上,我希望 LogCat 说“我们已经获得了 R.styleable.xxx”,而不是“我们已经获得了 1487214712442”

最佳答案

看这个方法:http://developer.android.com/reference/android/content/res/Resources.html#getResourceName(int )

Return the full name for a given resource identifier. This name is a single string of the form "package:type/entry".

关于android - 查找 R 的引用名称的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6874294/

相关文章:

android - 错误 : Error parsing XML: not well-formed (invalid token) . ..?

android - 长轮询与 Apple 推送通知服务和 Android C2DM

android - 当从另一个 Fragment/ViewModel 执行插入时,从 Room 返回的 Kotlin Flow 不会更新

java - 背景淡出并转到另一个页面

android - React-native <View> 组件的 "elevation"样式导致难看的阴影

android-layout - 如何创建 Android Google Play 的 GridView ,如动态加载不同尺寸图像的小部件

java - Android - 通用图像加载器中具有另一个 View 的 ImageView

android - 有什么地方可以让我从 Android 设计指南中获得典型的 XML 样式吗?

android - 用于打开带有越野地标显示的本地 Android 或 IOS map 的 HTML 链接

java - Android,我应该将内容居中吗?