标签: android-checkbox

我们如何在 jetpack compose 中创建一个圆形复选框?

通常可以使用修饰符将不同的形状分配给可组合项,但在此可组合项中并未这样做。

我希望图像中标记的部分是一个圆圈

在此输入图像描述

你可以看我下面写的代码

@Composable
fun StandardCheckbox(
    text: String = "",
    checked: Boolean,
    onCheckedChange: ((Boolean) -> Unit)?,
) {
    Row(
        Modifier.padding(horizontal = SpaceMedium)
    ) {
        Checkbox(
            modifier = Modifier
                .clip(CircleShape),
            checked = checked,
            onCheckedChange = onCheckedChange,
            enabled = true,
            colors = CheckboxDefaults.colors(
                checkedColor = MaterialTheme.colors.primary,
                checkmarkColor = MaterialTheme.colors.onPrimary,
                uncheckedColor = MaterialTheme.colors.onBackground.copy(alpha = 0.3f)
            )
        )
        Spacer(modifier = Modifier.width(SpaceSmall))
        Text(
            text = text,
            color = MaterialTheme.colors.primary,
            modifier = Modifier.clickable {
                if (onCheckedChange != null) {
                    onCheckedChange(!checked)
                }
            }
        )
    }
}
Run Code Online (Sandbox Code Playgroud)

android-checkbox android-jetpack android-jetpack-compose

4
推荐指数
2
解决办法
4267
查看次数

AlertDutog中的RadioButton或Or CheckBox

如何使用多个RadioButtonsCheckBoxesAlertDialog

android android-checkbox

3
推荐指数
1
解决办法
3045
查看次数

CheckBox按钮属性奇怪的结果为2.3.3 android

问题:为什么2.3.3中有额外的空间?

这是一个奇怪的行为,这就是为什么我认为我应该问.我的xml中有一个复选框,我有一个背景设置它.所以我把背景放在它的按钮属性中.

喜欢 android:button="@drawable/back_checkbox"

其中back_checkbox只是一个具有选中/未选中状态的选择器

现在在2.3.3: 在此输入图像描述

并在4.2: 在此输入图像描述

android android-checkbox

3
推荐指数
1
解决办法
441
查看次数

如何使用复选框创建Android设置菜单

我想创建一个首选项屏幕,其中有三个复选框;第一个是可单击的,而其他两个则只有在选中第一个后才能单击。

我怎样才能做到这一点?我看过本教程,但是只有一个复选框。谁能帮我?

android preferenceactivity android-preferences preferencescreen android-checkbox

3
推荐指数
1
解决办法
7368
查看次数

如何在android中达到限制时禁用复选框?

我有15个CheckBox,当我检查超过5时我必须卡住用户.我使用该方法OnCheckedChangeListener知道是否检查了一个项目,但我不知道如何在选择了5个项目后限制.

请参阅下面的代码:

int lengthBox = 15;
int lenghtCount = 0;  

// inside onCreate method
final CheckBox[] checkbox = new CheckBox[lengthBox];
OnCheckedChangeListener checker = new OnCheckedChangeListener(){ 
    @Override
    public void onCheckedChanged(CompoundButton cb, boolean b) {
        // How can I improve this condition?
        if(checkbox[0].isChecked() || checkbox[1].isChecked() || 
        checkbox[2].isChecked() || checkbox[3].isChecked() || 
        checkbox[4].isChecked() || checkbox[5].isChecked() || 
        checkbox[6].isChecked() || checkbox[7].isChecked() || 
        checkbox[8].isChecked() || checkbox[9].isChecked() || 
        checkbox[10].isChecked() || checkbox[11].isChecked() || 
        checkbox[12].isChecked() || checkbox[13].isChecked() || 
        checkbox[14].isChecked()) {  
            if(lenghtCount < 5){
                lenghtCount++; …
Run Code Online (Sandbox Code Playgroud)

android oncheckedchanged android-checkbox

3
推荐指数
1
解决办法
4593
查看次数

如何强制我的复选框文本不包装?

这就是我的LinearLayout(水平)行的样子:

在此输入图像描述

我希望复选框的文本在一行; 按钮不必那么宽 - 它们仍然有足够的空间,复选框文本延长了一点.在我的XML中:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <CheckBox
        android:id="@+id/ckbxAllow_New_Items"
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:checked="true"
        android:text="@string/checkbox_Allow_New_Items" />

    <Button
        android:id="@+id/btnOK"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/button_OK" />

    <Button
        android:id="@+id/btnCancel"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/button_Cancel" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

...需要更改以强制我的复选框文本不要换行?

UPDATE

遵循Der Golem的建议添加:

android:lines="1"
Run Code Online (Sandbox Code Playgroud)

...并且还将复选框的layout_weight从1更改为2(按钮设置为1)给了我想要的内容:

在此输入图像描述

android-layout android-linearlayout android-button android-checkbox

3
推荐指数
1
解决办法
2041
查看次数

将默认设计主题更改为自定义颜色

我是Android Studio的新手.作为初学者,我创建了一个简单的应用程序,仅用于测试目的并查看Android studio材料主题的外观.我目前正在使用最新版本即.L预览 - Studio 0.8.2版本.

在这里,我刚刚创建了textview,edittext,单选按钮和复选框.当我选择男性或女性时,它显示为天蓝色.我可以将天蓝色改为绿色或黄色吗?

我不知道这是什么名字.从图片中可以看到edittext,单选按钮和复选框选中状态为天蓝色.当我尝试单击或选择任何内容时,那些复选框或单选按钮需要从默认颜色更改为其他颜色,如绿色或黄色!

在res/values/styles.xml中,

<resources>
<!-- Base application theme. -->
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Material">
<item name="android:colorBackground">@color/custom_theme_color</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)

在Android Studio Manifest.xml中,

android:theme="@style/CustomTheme" >
Run Code Online (Sandbox Code Playgroud)

还有其他可能从默认天蓝色变为绿色或黄色或紫色吗?

Android Studio默认颜色

有没有其他方法可以将默认天蓝色主题更改为其他颜色,如粉红色或绿色?

我想学习,所以请给我一些关于如何做到这一点的建议?

android android-checkbox android-styles material-design

3
推荐指数
2
解决办法
1万
查看次数

如何设置复选框选中和禁用

我有这个代码来显示可供下载的语言列表:

public void onCreateDialog(ArrayList<String>fullLangArray, final ArrayList<String>codeLangArray) {

    final String[] items = fullLangArray.toArray(new String[fullLangArray.size()]);

    final ArrayList mSelectedItems = new ArrayList();

    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

    // Set the dialog title
    builder.setTitle("Updates...")
            .setMultiChoiceItems(items, null,
                    new DialogInterface.OnMultiChoiceClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int indexSelected,
                                            boolean isChecked) {
                            if (isChecked) {
                                  mSelectedItems.add(Utils.SERVER_ADDRESS + "/" + codeLangArray.get(indexSelected) + ".zip");
                            } else if (mSelectedItems.contains(indexSelected)) {
                                  mSelectedItems.remove(Integer.valueOf(indexSelected));
                            }
                        }
                    })

            .setPositiveButton("Download", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {

                    DownloadTask downloadTask = new …
Run Code Online (Sandbox Code Playgroud)

java android android-alertdialog android-checkbox

3
推荐指数
1
解决办法
1万
查看次数

android 复选框颜色改变

我有一个复选框,我想更改它的颜色。我附上一张图片以供更多理解。在此输入图像描述

我想将黑色方块的颜色更改为白色,就像文本“按跳过”一样。我的xml代码如下:

<CheckBox
 android:id="@+id/checkBox1"
 android:background="@drawable/tutorial_screen_edit_text_style"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:onClick="onCheckboxClicked"
 android:text="Press to Skip"
 android:textColor="@color/white"

 android:layout_alignParentTop="true"
 android:layout_alignParentRight="true"
 android:layout_alignParentEnd="true" />
Run Code Online (Sandbox Code Playgroud)

android android-checkbox

3
推荐指数
1
解决办法
3390
查看次数

取消选中 Android 中的所有复选框

我的布局中有一个清除按钮,单击该按钮我想取消选中线性布局内的所有复选框listview

XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id ="@+id/mainLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button
                android:id="@+id/btnClear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right|center"
                android:gravity="right|center"
                android:text="Remove" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">
            <ListView
                android:id="@+id/listview"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="5"
                android:cacheColorHint="@android:color/transparent"
                android:divider="#fff"
                android:dividerHeight="1dp"
                android:fadingEdge="none">
            </ListView>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在里面,listview我正在膨胀一个带有复选框的布局。现在btnClear我想取消选中所有复选框。我们该怎么做,请帮助我

android android-layout android-checkbox

2
推荐指数
1
解决办法
6824
查看次数