以编程方式设计Android的CheckBox [英] Programmatically styling Android's CheckBox

查看:50
本文介绍了以编程方式设计Android的CheckBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以扩展Activity并以编程方式添加一些View项的类。

I got a class which extends Activity and programmatically adding some View items.

CheckBox checkBox = new CheckBox(this, null, android.R.style.Widget_CompoundButton_Star);

我想设置一些样式类似于Android SDK的复选框。将其样式设置为Widget_CompoundButton_Star后,看不到任何复选框。虽然该SDK样式在直接放置到xml中时显然可以工作。

I'd like to set some checkBoxes styled as the Android SDK stars. I can't see any check box after I set its style to that Widget_CompoundButton_Star. Although that SDK style apparently works when directly placing in a xml.

我在这里遗漏了什么吗? THX

Am I missing something here? THX

//正如Pragnani所说。代替使用 android.R.attr.starStyle

// As Pragnani said. Using android.R.attr.starStyle instead works.

推荐答案

I我已经到达这里寻找样式化CheckBox而不是Drawable的文本,而我通过另一种方式找到了解决方案。但是,嘿!让我分享未来的解决方案。

I've arrived here looking for styling the text of the CheckBox instead of the Drawable, and I find the solution by another way. But hey! Let me share the solution to the myself of the future.

而不是:

CheckBox cb = new CheckBox(this, null, R.style.yourstyle);

使用:

CheckBox cb = new CheckBox(this);
cb.setTextAppearance(this, R.style.yourstyle);

希望它有助于解决问题的主题!

Hope it helps to solve the topic of the question!

这篇关于以编程方式设计Android的CheckBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆