【发布时间】:2023-04-02 11:40:01
【问题描述】:
我想解析 android activity_main.xml 并务实地在其中添加我的视图的自定义属性标签。
例如:(原创)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
<view
android:layout_width="match_parent"
android:layout_height="wrap_content"
class="com.test.compoundviewcreation.Slider"
android:id="@+id/view4"/>
</RelativeLayout>
修改后:(添加自定义:sliderLabel标签)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
<view
android:layout_width="match_parent"
android:layout_height="wrap_content"
class="com.test.compoundviewcreation.Slider"
android:id="@+id/view4"
custom:sliderLabel="Custom SLider Label"/>
</RelativeLayout>
我尝试使用 DOM Parser,但它无法解析它并显示 xml doc 为空。有什么想法吗?
【问题讨论】:
-
为什么以编程方式?有什么要求?为每个
<view>添加相同的属性?有了提供的信息,我会手动完成。 -
@Birei 因为不想手动修改。 Android Studio 布局设计器属性面板仅显示 android 属性,不显示自定义属性。我将通过一个简单的 java 应用程序创建另一个属性面板,它允许输入自定义属性。所以,我需要解析这个 XML 文件。是的,我想为不同的自定义视图添加相同的属性。
-
我的主管不想手动操作,我想为他提供一种解决方案。