Android为CheckBox设置Style

MainActivity如下:

package cc.testcheckboxstyle;

import android.os.Bundle;
import android.app.Activity;
/**
 * Demo描述:
 * 为CheckBox设置Style
 */
public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}

}

main.xml如下:

<RelativeLayout 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"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="测试CheckBox的Style"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dip"
    />

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="100dip"
        android:layout_height="100dip"
        android:layout_centerInParent="true"
        style="@style/CheckBoxStyle"
    />

</RelativeLayout>

styles.xml如下:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="AppBaseTheme" parent="android:Theme.Light">
    </style>

    <style name="AppTheme" parent="AppBaseTheme">
    </style>

    <style name="CheckBoxStyle" parent="@android:style/Widget.CompoundButton.CheckBox">
        <item name="android:button">@drawable/checkbox_background</item>
    </style>

</resources>

checkbox_background.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_checked="true" android:drawable="@drawable/on"/>
   <item android:state_checked="false" android:drawable="@drawable/off"/>
</selector>
时间: 2024-08-04 00:19:08

Android为CheckBox设置Style的相关文章

动态-android怎么用代码给checkbox设置style

问题描述 android怎么用代码给checkbox设置style 就是动态改变checkbox style 让选中和不选中的效果改变 是用java代码动态设置 解决方案 这个是给checkbox添加背景图的 ch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, bo

Android 在Java代码中设置style属性(以ProgressBar为例)

在andriod开发中,很大一部分都要与资源打交道,比如说:图片,布局文件,字符串,样式等等.这给我们想要开发一些公共的组件带来很大的困难,因为公共的组件可能更愿意以jar包的形式出现.但是java的jar包中只允许出现java代码而不能出现资源. 当我们想要以jar包的形式提供我们自己开发的公共组件时,我们就需要把以代码的形式创建资源. 下面提供一个使用全Java代码的形式创建一个ProgressBar. ProgressBar默认的样式是一个圈圈,我们要想其显示为进度条的样式可以在布局文件中

动态-android如何在代码中给组件设置style?

问题描述 android如何在代码中给组件设置style? RT,不要提TextView了,全部都是告诉我TextView.setTextAppearance(),我要的是别的组件,比如LinearLayout之类的,如何在代码中设置他的style 我看了下源代码,style都是在初始化的时候通过TypedArray解析style然后一条条属性加进去的,那么有没有类似style这样的方法,可以动态设置的 没有C币了,多多包涵下,谢谢了 解决方案 参考Android: set view style

android文字阴影效果设置

[html] view plaincopy <TextView  android:id="@+id/tvText1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="text1"        android:textSize="30sp&quo

Android Studio简单设置(转)

Android Studio 简单设置 界面设置 默认的 Android Studio 为灰色界面,可以选择使用炫酷的黑色界面.Settings --> Appearance --> Theme ,选择 Darcula 主题即可. 字体设置 系统字体设置 如果你的Android Studio界面中,中文显示有问题,或者选择中文目录显示有问题,或者想修改菜单栏的字体,可以这么设置.Settings --> Appearance ,勾选 Override default fonts by (

android-安卓的supportActionBar怎么设置style

问题描述 安卓的supportActionBar怎么设置style 如题.因为要用到ViewPager需要用support包,然后那一个Activity的所有 包括actionBar都是support的,然后我发现supportActionBar的style没法设置,按照常规设置style的方式设置出来没效果.直接贴代码吧 <style name=""AppCompatTheme"" parent=""Base.Theme.AppCompa

Android 使用SystemBarTint设置状态栏颜色

   做项目时,发现APP的状态栏是系统默认的颜色,突然想到,为啥别的APP是自己设置的颜色(和APP本身很相搭),于是也想给自己的APP设置系统状态栏的颜色,更加美美哒...   搜了下,发现原来设置状态栏居然有个很高大上的名字(听不懂的都是高大上)--沉浸式状态栏,Android4.4以后开始支持沉浸式状态栏, 继续搜索,发现,有一个很简单的开源项目--SystemBarTint,可以很完美的支持沉浸式状态栏.     SystemBarTint地址: https://github.com/

android SeekBar 样式设置

  UI参考                     Xml代码   <SeekBar          android:id="@+id/seekbar"          style="?android:attr/progressBarStyleHorizontal"          android:layout_width="fill_parent"          android:layout_height="wrap

android中checkbox的文本隐藏

问题描述 android中checkbox的文本隐藏 在checkbox上添加了文本,现在想隐藏起来(需要的时候获取),请教怎么做 将背景设置成白色有点不靠谱 解决方案 可以试试设置一个imageview,默认背景为A图(点击时将A图替换为B图,以达到类似checkbox点击效果),再在imageview的右侧设置textview. 当imageview点击时对应控制textview的显隐即可.