2.07ToggleButton(开关按钮) |
您所在的位置:网站首页 › widget开关 › 2.07ToggleButton(开关按钮) |
ToggleButton(开关按钮)-Switch(开关)-UI组件-AndroidToggleButton(开关按钮)Switch(开关)案例TOC
ToggleButton(开关按钮)-Switch(开关)-UI组件-Android
ToggleButton(开关按钮)
属性名
说明
android:disabledAlpha
设置按钮在禁用时的透明度
android:textOff
按钮没有被选中时显示的文字
android:textOn
按钮被选中时显示的文字 另外,除了这个我们还可以自己写个selector,然后设置下Background属性即可
Switch(开关)
属性名
说明
android:showText
设置on/off的时候是否显示文字,boolean
android:splitTrack
是否设置一个间隙,让滑块与底部图片分隔,boolean
android:switchMinWidth
设置开关的最小宽度
android:switchPadding
设置滑块内文字的间隔
android:switchTextAppearance
设置开关的文字外观
android:textOff
按钮没有被选中时显示的文字
android:textOn
按钮被选中时显示的文字
android:textStyle
文字风格,粗体,斜体写划线那些
android:track
底部的图片
android:thumb
滑块的图片
android:typeface
设置字体,默认支持这三种:sans, serif, monospace;除此以外还可以使用 其他字体文件(*.ttf)
案例
滑块 底部 点击事件 import android.os.Bundle; import android.widget.CompoundButton; import android.widget.Switch; import android.widget.Toast; import android.widget.ToggleButton; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; public class SwitchActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener { private ToggleButton tbtn_open; private Switch swh_status; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.switch_layout); tbtn_open = (ToggleButton) findViewById(R.id.tbtn_open); swh_status = (Switch) findViewById(R.id.swh_status); tbtn_open.setOnCheckedChangeListener(this); swh_status.setOnCheckedChangeListener(this); } @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { switch (compoundButton.getId()) { case R.id.tbtn_open: if (compoundButton.isChecked()) { Toast.makeText(this, "打开声音", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "关闭声音", Toast.LENGTH_SHORT).show(); } break; case R.id.swh_status: if (compoundButton.isChecked()) { Toast.makeText(this, "开关:ON", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "开关:OFF", Toast.LENGTH_SHORT).show(); } break; } } } |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |