收藏文章 楼主

button按钮控件效果

版块:android   类型:精华/置顶   作者:小绿叶技术博客   查看:3987   回复:0   获赞:2   时间:2019-04-04 10:09:39
<!--

消息上面一行代码是:将一行分成多个等份,占其中1份
消息下面一行代码是:文本居中
最后两行代码,第一个是引用/drawable/xiaoxi.xml中的效果,点击前和点击后
后一行是引用/drawable/text_color.xml背景颜色
-->
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="消息"
android:gravity="center"
android:button="@null"
android:drawableTop="@drawable/xiaoxi"
android:textColor="@drawable/text_color"


/>
res/drawbl文件夹中文件内容
drawable/xiaoxi
------------------------
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_checked="false" android:drawable="@mipmap/weixin_normal">
<item android:state_checkable="true" android:drawable="@mipmap/weixin_pressed">
</selector>
=========================================================================================
text_color.xml
----------------------
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_checked="false" android:color="@color/black">
<item android:state_checked="true" android:color="@color/green">
</selector>
================================================================================================

全局背景颜色文件
res/values/colors.xml
------------------------
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="black">#000000</color>
<color name="white">#FFFFFF</color>
<color name="green">#00FF00</color>
</resources>
==================================================
文件:values/actity_xiaoxi.xml
界面左右排列
android:orientation="horizontal"
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".xiaoxi">

<RadioGroup
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent" >

<!--

消息上面一行代码是:将一行分成多个等份,占其中1份
消息下面一行代码是:文本居中
最后两行代码,第一个是引用/drawable/xiaoxi.xml中的效果,点击前和点击后
后一行是引用/drawable/text_color.xml背景颜色
-->
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/xiaoxi"
android:gravity="center"
android:text="消息"
android:textColor="@drawable/text_color" />

<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/lianxiren"
android:gravity="center"
android:text="联系人"
android:textColor="@drawable/text_color" />
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/dongtai"
android:gravity="center"
android:text="动态"
android:textColor="@drawable/text_color" />

</RadioGroup>

</android.support.constraint.ConstraintLayout>

提供企业建站服务,免费网防系统,提交信息登录 http://yundun.ddoss.cn 邮箱: proposal@ddoss.cn 
回复列表
默认   热门   正序   倒序

回复:button按钮控件效果

头像

用户名:

粉丝数:

签名:

资料 关注 好友 消息