0

下面是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:checkMark="@drawable/checking_icon"
    android:orientation="vertical"
    android:padding="8dp"
    android:textSize="18sp" />

对于@drawable/checking_icon上面的xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/enable_32" android:state_checked="true"/>
    <item android:drawable="@drawable/disable_32"/>

</selector>

如何以编程方式创建上述 2 个 xml?

4

1 回答 1

0

您可以简单地从 XML 文件中创建 CheckedTextView,方法是像这样膨胀它

LayoutInflater.from(context).inflate(R.layout.myfile, null);

应该就是这样。如果你想设置drawable做这样的事情

checkedTextView.setCheckMarkDrawable(getResources().getDrawable(R.drawable.filename));
于 2013-12-27T13:41:56.410 回答