xamarin - 如何以编程方式将选择器设置为复选框
问题描述
我需要将选择器设置为以编程方式创建的复选框,这样:
var cbAll = new CheckBox(Activity);
LinearLayout.LayoutParams llAll = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
cbAll.Text = "All zones";
llAll.LeftMargin = 27;
llAll.TopMargin = 24;
cbAll.ButtonDrawable = //what to put here?
我在可绘制文件夹中的选择器(名为 cb_edit.xml):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/cb_active" android:state_checked="true" />
<item android:drawable="@drawable/cb_default" android:state_checked="false"/>
</selector>
解决方案
我不知道你到底在尝试什么。但是如果你设置背景然后试试这个
cbAll.SetBackgroundResource( Resource.Drawable.cb_edit);
推荐阅读
- java - 如何从 Firebase 实时数据库中检索具有 UID 的特定用户的特定数据
- vb.net - 是否可以在visual basic中获得下周一和周日的日期?
- python - 数组中的 Python 对象
- salt-stack - 如何在不运行命令的情况下检查命令将针对哪些奴才?
- java - 更新数组列表的最佳实践(Java/Spring Boot)
- mysql - MySQL - 总和正在成倍增加
- bro - Zeek 不存储文件,即使在加载脚本之后也是如此。我错过了什么?
- node.js - 何时使用 container.get 与构造函数 @inject?
- python - Tensorflow 和 Tensorflow-Probability NotFoundError:没有算法有效![操作:Conv2D]
- python - Discord - 截图嵌入消息