android:button = @null in radiobutton

本文介绍了一种去除Android中RadioButton默认圆点的方法,并通过调整padding属性来优化布局间距,确保在不同设备上的显示效果一致。

radiobutton的圆点去掉使用button=@null,但是去掉后小圆点仍然占据位置(在部分手机上重现)。

布局文件:

 <RadioGroup
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:background="#fff"
                android:orientation="horizontal"
                android:paddingBottom="5dp"
                android:paddingTop="5dp" >

                <RadioButton
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:button="@null"
                    android:gravity="center"
                    android:paddingLeft="0dp"
                    android:text="详情"
                    android:textSize="14sp" />

                <RadioButton
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:button="@null"
                    android:gravity="center"
                    android:paddingLeft="0dp"
                    android:text="目录"
                    android:textSize="14sp" />

                <RadioButton
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:button="@null"
                    android:gravity="center"
                    android:paddingLeft="0dp"
                    android:text="评论"
                    android:textSize="14sp" />
            </RadioGroup>
需要注意这条属性:
android:paddingLeft="0dp"

加上即可。

请用<!-- 支出类别选择图标组 --> <!-- 支出类别图标组 --> <LinearLayout android:id="@+id/expense_category_group_search_1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginBottom="16dp"> <ImageButton android:id="@+id/category_food" android:layout_width="69dp" android:layout_height="wrap_content" app:srcCompat="@mipmap/hs_canyin_f" android:background="@color/button_default" /> <ImageButton android:id="@+id/category_shopping" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_gouwu_f" /> <ImageButton android:id="@+id/category_utilities" android:layout_width="69dp" android:layout_height="wrap_content" app:srcCompat="@mipmap/hs_shuidianfei_f" android:background="@color/button_default" /> <ImageButton android:id="@+id/category_phone" android:layout_width="69dp" android:layout_height="wrap_content" app:srcCompat="@mipmap/hs_tongxun_f" android:background="@color/button_default" /> <ImageButton android:id="@+id/category_entertainment" android:layout_width="69dp" android:layout_height="wrap_content" app:srcCompat="@mipmap/hs_yule_f" android:background="@color/button_default" /> </LinearLayout> <LinearLayout android:id="@+id/expense_category_group_search_2" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginBottom="16dp"> <ImageButton android:id="@+id/category_other_outcome" android:layout_width="69dp" android:layout_height="wrap_content" app:srcCompat="@mipmap/hs_qt_f" android:background="@color/button_default" /> </LinearLayout> <!-- 收入类别图标组 --> <LinearLayout android:id="@+id/income_category_group_search_1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginBottom="16dp" android:visibility="gone"> <ImageButton android:id="@+id/category_salary" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_xinzi_f" /> <ImageButton android:id="@+id/category_collect_debt" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_shouzhai_f" /> <ImageButton android:id="@+id/category_bonus" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_jiangjin_f" /> <ImageButton android:id="@+id/category_investment" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_touzi_f" /> <ImageButton android:id="@+id/category_accident" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_yiwaisuode_f" /> </LinearLayout> <LinearLayout android:id="@+id/income_category_group_search_2" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginBottom="16dp" android:visibility="gone"> <ImageButton android:id="@+id/category_other_income" android:layout_width="69dp" android:layout_height="wrap_content" android:background="@color/button_default" app:srcCompat="@mipmap/hs_qita_f" /> </LinearLayout> 代替<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp"> <!-- 返回按钮 --> <Button android:id="@+id/back_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="返回" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> <!-- 标题 --> <TextView android:id="@+id/search_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="查询记录" android:textSize="24sp" android:textStyle="bold" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toStartOf="@id/back_button" /> <!-- 输入金额框 --> <EditText android:id="@+id/search_input" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="金额" android:inputType="numberDecimal" android:digits="0123456789." android:textSize="16sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toStartOf="@id/by_amount_button" app:layout_constraintTop_toBottomOf="@id/search_title" android:layout_marginTop="16dp"/> <!-- 按金额查找按钮 --> <Button android:id="@+id/by_amount_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按金额查找" app:layout_constraintStart_toEndOf="@id/search_input" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/back_button" android:layout_marginStart="8dp"/> <!-- 收入/支出按钮 --> <Button android:id="@+id/income_button" android:layout_width="0dp" android:layout_height="wrap_content" android:text="收入明细" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toStartOf="@id/expense_button" app:layout_constraintTop_toBottomOf="@id/by_amount_button" android:layout_marginTop="16dp"/> <Button android:id="@+id/expense_button" android:layout_width="0dp" android:layout_height="wrap_content" android:text="支出明细" app:layout_constraintStart_toEndOf="@id/income_button" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/by_amount_button" android:layout_marginTop="16dp"/> <!-- 日期选择按钮 --> <Button android:id="@+id/date_picker_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="选择日期" app:layout_constraintTop_toBottomOf="@id/income_button" android:layout_marginTop="16dp"/> <!-- 类别单选组:两行三列布局 --> <RadioGroup android:id="@+id/category_group" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="8dp" app:layout_constraintTop_toBottomOf="@id/date_picker_button" android:layout_marginTop="16dp"> <RadioButton android:id="@+id/category_food" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="餐饮" /> <RadioButton android:id="@+id/category_shopping" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="购物" /> <RadioButton android:id="@+id/category_utilities" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="水电" /> <RadioButton android:id="@+id/category_phone" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="话费" /> <RadioButton android:id="@+id/category_entertainment" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="娱乐" /> <RadioButton android:id="@+id/category_other" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="其他" /> </RadioGroup> <!-- 查询结果表格 --> <ScrollView android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintTop_toBottomOf="@id/category_group" app:layout_constraintBottom_toBottomOf="parent" android:layout_marginTop="16dp"> <TableLayout android:id="@+id/result_table" android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="*" /> </ScrollView> </androidx.constraintlayout.widget.ConstraintLayout> 的radiogroup部分
06-28
package com.example.bulbpage.editpreset import android.content.res.ColorStateList import android.graphics.Color import androidx.fragment.app.viewModels import android.os.Bundle import android.util.Log import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Button import androidx.core.content.ContextCompat import com.example.bulbpage.R import com.example.bulbpage.databinding.FragmentEditPresetBinding class EditPresetFragment : Fragment() { private var _binding: FragmentEditPresetBinding? = null private val binding get() = _binding!! override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { _binding = FragmentEditPresetBinding.inflate(inflater, container, false) return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) // 默认选中 A binding.buttonA.isChecked = true binding.optionGroup.setOnCheckedChangeListener { _, checkedId -> when (checkedId) { R.id.buttonA -> { Log.d("Click","ClickA") binding.buttonA.backgroundTintList = ColorStateList.valueOf( ContextCompat.getColor(requireContext(), R.color.skyblue) ) binding.buttonA.setTextColor(Color.WHITE) binding.buttonB.backgroundTintList = ColorStateList.valueOf(Color.WHITE) binding.buttonB.setTextColor(Color.BLACK) } R.id.buttonB -> { Log.d("Click","ClickB") binding.buttonB.backgroundTintList = ColorStateList.valueOf( ContextCompat.getColor(requireContext(), R.color.skyblue) ) binding.buttonB.setTextColor(Color.WHITE) binding.buttonA.backgroundTintList = ColorStateList.valueOf(Color.WHITE) binding.buttonA.setTextColor(Color.BLACK) } } } } override fun onDestroyView() { super.onDestroyView() _binding = null } }<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context=".editpreset.EditPresetFragment"> <ImageView android:id="@+id/imageView3" android:layout_width="24dp" android:layout_height="24dp" android:scaleType="centerInside" android:src="@drawable/close" android:layout_marginStart="16dp" app:layout_constraintBottom_toBottomOf="@+id/edit_auto_white" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/edit_auto_white" /> <TextView android:id="@+id/edit_auto_white" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="16dp" android:text="Edit Auto White" android:textSize="20dp" app:layout_constraintStart_toEndOf="@+id/imageView3" app:layout_constraintTop_toTopOf="parent"> </TextView> <ImageView android:layout_width="24dp" android:layout_height="24dp" android:scaleType="centerInside" android:src="@drawable/ok" android:layout_marginEnd="16dp" app:layout_constraintBottom_toBottomOf="@+id/edit_auto_white" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="@+id/edit_auto_white" app:layout_constraintVertical_bias="1.0" /> <!-- res/layout/fragment_tab_selector.xml --> <androidx.cardview.widget.CardView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="16dp" app:cardCornerRadius="50dp" app:cardElevation="4dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/edit_auto_white"> <RadioGroup android:id="@+id/optionGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="8dp"> <com.google.android.material.button.MaterialButton android:id="@+id/buttonA" android:layout_width="120dp" android:layout_height="48dp" android:stateListAnimator="@null" android:checkable="true" android:text="A" android:textColor="@android:color/black" app:backgroundTint="@android:color/white" /> <com.google.android.material.button.MaterialButton android:checkable="true" android:id="@+id/buttonB" android:layout_width="120dp" android:layout_height="48dp" android:stateListAnimator="@null" android:text="B" android:textColor="@android:color/black" app:backgroundTint="@android:color/white" /> </RadioGroup> </androidx.cardview.widget.CardView> </androidx.constraintlayout.widget.ConstraintLayout>仍然没有打印日志
08-26
等一下,这部分代码我觉得应该结合一下他的java文件,java文件不改,只是说布局文件修改后id那些别乱套。还是一样,仅修改布局成constraintlayout,使用guideline和space来决定组件跟组件之间的距离。但是组件内容我不想改变。首先activity_survey.xml代码如下:<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp" android:fitsSystemWindows="true" android:background="@color/surface_background"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <!-- 问题1:评分 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_marginBottom="32dp" android:text="🚌 用户体验调研" android:textColor="#777777" android:textSize="24sp" android:textStyle="bold" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1. 您对本应用的整体评分是?" android:textStyle="bold" android:textColor="#777777" android:layout_marginBottom="8dp" /> <RadioGroup android:id="@+id/radioGroupRating" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="24dp"> <RadioButton android:text="⭐ 1分 - 非常不满意" android:textColor="@color/black" android:id="@+id/rb1" android:layout_height="match_parent" android:layout_width="match_parent"/> <RadioButton android:text="⭐⭐ 2分 - 不满意" android:textColor="@color/black" android:id="@+id/rb2" android:layout_height="match_parent" android:layout_width="match_parent"/> <RadioButton android:text="⭐⭐⭐ 3分 - 一般" android:textColor="@color/black" android:id="@+id/rb3" android:layout_height="match_parent" android:layout_width="match_parent"/> <RadioButton android:text="⭐⭐⭐⭐ 4分 - 满意" android:textColor="@color/black" android:id="@+id/rb4" android:layout_height="match_parent" android:layout_width="match_parent"/> <RadioButton android:text="⭐⭐⭐⭐⭐ 5分 - 非常满意" android:textColor="@color/black" android:id="@+id/rb5" android:layout_height="match_parent" android:layout_width="match_parent"/> </RadioGroup> <!-- 问题2:满意度 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2. 您对以下哪些方面或功能感到满意?(可多选)" android:textColor="#777777" android:textStyle="bold" android:layout_marginBottom="8dp" /> <CheckBox android:id="@+id/cb_ui" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="界面美观易用" android:textColor="@color/black"/> <CheckBox android:id="@+id/cb_speed" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="加载速度快" android:textColor="@color/black"/> <CheckBox android:id="@+id/cb_information" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="查询信息准确" android:textColor="@color/black"/> <CheckBox android:id="@+id/cb_other" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="其他" android:textColor="@color/black"/> <!-- 问题3:建议 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3. 您有什么改进建议?" android:textColor="#777777" android:textStyle="bold" android:layout_marginTop="24dp" android:layout_marginBottom="8dp" /> <EditText android:id="@+id/et_suggestion" android:layout_width="match_parent" android:layout_height="120dp" android:gravity="top" android:hint="请输入您的建议..." android:textColorHint="#777777" android:textColor="@color/black" android:inputType="textMultiLine" android:minLines="3" /> <!-- 提交按钮 --> <Button android:id="@+id/btn_submit" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="提交反馈" android:textSize="18sp" android:layout_marginTop="32dp" style="?android:attr/buttonStyle" /> </LinearLayout> </ScrollView> SurveyActivity代码如下:package com.example.bus; import android.os.Bundle; import android.widget.*; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.app.AlertDialog; public class SurveyActivity extends AppCompatActivity { private static final String FEEDBACK_EMAIL = "your_email@example.com"; // 修改为你自己的邮箱地址 private static final String EMAIL_SUBJECT = "用户调研反馈"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_survey); // 显示 ActionBar 上的返回箭头 if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle("用户调研"); } // 绑定控件 RadioGroup radioGroupRating = findViewById(R.id.radioGroupRating); CheckBox cbUi = findViewById(R.id.cb_ui); CheckBox cbSpeed = findViewById(R.id.cb_speed); CheckBox cbInformation = findViewById(R.id.cb_information); CheckBox cbOther = findViewById(R.id.cb_other); EditText etSuggestion = findViewById(R.id.et_suggestion); Button btnSubmit = findViewById(R.id.btn_submit); // 提交按钮点击事件 btnSubmit.setOnClickListener(v -> { // 获取评分 int selectedId = radioGroupRating.getCheckedRadioButtonId(); String rating = "未评分"; if (selectedId == R.id.rb1) rating = "1分"; else if (selectedId == R.id.rb2) rating = "2分"; else if (selectedId == R.id.rb3) rating = "3分"; else if (selectedId == R.id.rb4) rating = "4分"; else if (selectedId == R.id.rb5) rating = "5分"; // 获取满意度选项 StringBuilder satisfaction = new StringBuilder(); if (cbUi.isChecked()) satisfaction.append("界面美观易用, "); if (cbSpeed.isChecked()) satisfaction.append("加载速度快, "); if (cbInformation.isChecked()) satisfaction.append("功能丰富实用, "); if (cbOther.isChecked()) satisfaction.append("其他, "); String satisfactionStr = satisfaction.length() > 0 ? satisfaction.substring(0, satisfaction.length() - 2) : "无"; // 获取建议 String suggestion = etSuggestion.getText().toString().trim(); if (suggestion.isEmpty()) suggestion = "无"; // 拼接邮件正文 String body = String.format( "用户调研反馈\n\n" + "【整体评分】\n%s\n\n" + "【满意项】\n%s\n\n" + "【改进建议】\n%s\n\n" + "---\n来自 Android 客户端自动提交", rating, satisfactionStr, suggestion ); // 发送邮件 sendEmail(body); }); } /** * 发送邮件核心方法 */ private void sendEmail(String body) { try { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); // 纯文本 // 设置收件人邮箱(必须为字符串数组) intent.putExtra(Intent.EXTRA_EMAIL, new String[]{FEEDBACK_EMAIL}); // 设置主题和正文 intent.putExtra(Intent.EXTRA_SUBJECT, EMAIL_SUBJECT); intent.putExtra(Intent.EXTRA_TEXT, body); // 启动系统选择器 startActivity(Intent.createChooser(intent, "选择邮件客户端")); } catch (Exception e) { Toast.makeText(this, "无法启动邮件应用,请安装Gmail、QQ邮箱等程序", Toast.LENGTH_LONG).show(); } } @Override public boolean onSupportNavigateUp() { onBackPressed(); // 执行返回操作 return true; // 表示已处理该事件 } }
最新发布
11-07
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值