RadioButton、CheckBox去除选中时的动画阴影效果

CheckBox默认选中和取消选中都有个灰色阴影效果,去除方法如下:

方法一:(评论区建议)

直接使用background属性。颜色或图片,使用AS3.1版本,还是需要添加android:button="@null")

android:background="@drawable/ic_launcher"
android:background="@android:color/transparent"

方法二:(AS3.0上不能使用)

1.在CheckBox的布局中添加button属性

android:button="@null"

2.在res/drawable文件夹下新建一个selector文件check_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_launcher" android:state_checked="true"></item>
    <item android:drawable="@drawable/ic_launcher_round" android:state_checked="false"></item>
</selector>
解析:该xml文件中有两个item,第一个是控件选中状态为true时展示的图片为ic_launcher,第二个是选中状态为false的情况。

selsector不但有是否选中,还有许多状态,如:state_focused 是否聚焦

3.在CheckBox的布局中添加background属性

android:background="@drawable/check_selector"
<CheckBox
        android:id="@+id/check_child"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:checked="false"
        android:gravity="center"
        android:button="@null"
        android:background="@drawable/check_selector"
        android:layout_centerVertical="true"
        />

运行后,阴影效果将不会再显示


  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
要实现在QT中点击按钮保存当前页面checkbox选中效果radiobutton选中效果、lineedit输入内容并退出当前页面,你可以按照以下步骤进行: 1. 在QT设计师中添加需要使用的控件,如QCheckBox、QRadioButton和QLineEdit等。 2. 在代码中定义需要保存的变量,如bool类型的变量保存QCheckBox选中状态,int类型的变量保存QRadioButton选中的编号,QString类型的变量保存QLineEdit输入内容。 3. 在按钮的clicked信号的槽函数中,使用isChecked()函数获取QCheckBox选中状态,使用isChecked()和objectName()函数获取QRadioButton选中的编号,使用text()函数获取QLineEdit的输入内容。 4. 将获取到的变量作为参数传入保存函数中进行保存。 5. 在保存完成后,调用close()函数退出当前页面。 以下是一个示例代码: ``` void MainWindow::on_saveButton_clicked() { // 获取QCheckBox选中状态 bool checkBoxState = ui->checkBox->isChecked(); // 获取QRadioButton选中的编号 int radioButtonId = -1; if (ui->radioButton_1->isChecked()) { radioButtonId = 1; } else if (ui->radioButton_2->isChecked()) { radioButtonId = 2; } else if (ui->radioButton_3->isChecked()) { radioButtonId = 3; } // 获取QLineEdit输入内容 QString lineEditContent = ui->lineEdit->text(); // 调用保存函数,将获取到的变量作为参数传入 saveData(checkBoxState, radioButtonId, lineEditContent); // 关闭当前页面 this->close(); } ``` 以上就是实现在QT中点击按钮保存当前页面checkbox选中效果radiobutton选中效果、lineedit输入内容并退出当前页面的一般步骤。具体的实现方式可能因为你的具体需求而有所不同。
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值