android checkbox文字,Android CheckBox text not displaying

在尝试为Android应用程序动态创建CheckBox时遇到了文本不显示的问题。代码中已为LinearLayout 'register_attracted_to' 添加了两个CheckBox,分别设置文本为'Male'和'Female',但运行时CheckBox的文字没有正确显示。尽管垂直布局正常工作,CheckBox文本依然缺失。问题可能出在布局或代码的其他部分。附带截图展示了问题的实际情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I'm trying to dynamically create some CheckBoxes in one of my Android activities, but it's not rendering the text.

Here is my simplified code...

Layout XML:

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:padding="10dip">

...

android:id="@+id/register_attracted_to"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="vertical" />

...

Activity code:

final LinearLayout attractedTo = (LinearLayout) findViewById(R.id.register_attracted_to);

final CheckBox male = new CheckBox(this);

male.setText("Male");

attractedTo.addView(male);

final CheckBox female = new CheckBox(this);

female.setText("Female");

attractedTo.addView(female);

My "real" code is a little more complex (any dynamic) than this, which is why I haven't simply included the checkboxes in the layout itself. However, even dumbing down my code still doesn't render the checkbox text properly.

Here's a screenshot to demonstrate (see the "Attracted To" section), with a little extra to demonstrate that my vertical layout appears to be working properly otherwise:

9232c053e136d5f3fcf31dc1de7482c8.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值