https://www.hdzikao.com

安卓开发 ToggleButton这个控件 代码要怎么写 可以直接控制这个开关开 ...(如何修改checkBox中button的大小)【compoundbutton的2个解答】

[导读] 大家好,今天小热关注到一个比较有意思的话题,就是关于CompoundButton的问题,于是小编就整理了2个相关介绍CompoundButton的解答,让我们一起看看吧。 文章目录: 安卓开发 ToggleButton这个控件

安卓开发 ToggleButton这个控件 代码要怎么写 可以直接控制这个开关开 ...(如何修改checkBox中button的大小)【compoundbutton的2个解答】

大家好,今天小热关注到一个比较有意思的话题,就是关于CompoundButton的问题,于是小编就整理了2个相关介绍CompoundButton的解答,让我们一起看看吧。

文章目录:

  1. 安卓开发 ToggleButton这个控件 代码要怎么写 可以直接控制这个开关开 ...
  2. 如何修改checkBox中button的大小

一、安卓开发 ToggleButton这个控件 代码要怎么写 可以直接控制这个开关开 ...

toggleButton=(ToggleButton)findViewById(R.id.toggleButton);

  toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener(){

  public void onCheckedChanged(CompoundButton buttonView,

  boolean isChecked) {

  toggleButton.setChecked(isChecked);

  imageView.setImageResource(isChecked?R.drawable.bulb_on:R.drawable.bulb_off);

  }

  });

二、如何修改checkBox中button的大小

您好,很高兴能帮助您,

自定义样式 在values中创建styles.xml:

<?xml version="1.0" encoding="utf-8"?>

<resources>

<style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">

<item name="android:button">@drawableselector</item>

<item name="android:paddingLeft">20.0dip</item>

<item name="android:maxHeight">10.0dip</item>

</style>

</resources>

<CheckBox

android:layout_width="wrap_content"

android:layout_height="wrap_content"

style="@style/MyCheckBox"

/>

你的采纳是我前进的动力,还有不懂的地方,请你继续“追问”!

如你还有别的问题,可另外向我求助;答题不易,互相理解,互相帮助!

到此,以上就是小编对于CompoundButton的问题就介绍到这了,希望介绍关于CompoundButton的2点解答对大家有用。

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

相关文章阅读