当前位置: 首页 > news >正文

济南企业营销型网站建设价格今日国际新闻10条

济南企业营销型网站建设价格,今日国际新闻10条,手机网站怎样建设,网上的毕业设计代做网站靠谱吗CheckBox选择Or不选,是个问题! 前言 前面我们讲过了RadioButton与RadioGroup,利用单选按钮组的属性来实现仿微信底部Tab切换的效果。对比记忆一下,今天我们来讲解第二个类似的控件CheckBox,按照惯例先看下它的类继承…

CheckBox选择Or不选,是个问题!

前言

前面我们讲过了RadioButtonRadioGroup,利用单选按钮组的属性来实现仿微信底部Tab切换的效果。对比记忆一下,今天我们来讲解第二个类似的控件CheckBox,按照惯例先看下它的类继承关系如下:

public class CheckBox extends CompoundButton
java.lang.Object↳ android.view.View↳ android.widget.TextView↳ android.widget.Button↳ android.widget.CompoundButton↳ android.widget.CheckBox

我们发现CheckBoxRadioButton有相同的继承关系,所以CheckBox也是一个具有选中效果的控件,通常我们称它为**复选框**。

基本使用

先来展示一段代码,展示下效果。

<?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"android:layout_width="match_parent"android:layout_height="match_parent"><CheckBoxapp:layout_constraintHorizontal_chainStyle="packed"android:id="@+id/cb_hobby"android:layout_width="wrap_content"android:layout_height="wrap_content"android:checked="true"app:layout_constraintRight_toLeftOf="@id/tv_hobby"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintTop_toTopOf="parent" /><TextViewandroid:id="@+id/tv_hobby"android:layout_width="wrap_content"android:layout_marginLeft="5dp"android:layout_height="wrap_content"app:layout_constraintTop_toTopOf="parent"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toRightOf="@id/cb_hobby"android:text="游泳"app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>

这里我们使用了前面博文内容讲到的ConstraintLayout,实现了CheckBox和TextView一起居中整个父布局的效果。如果你还不是很熟悉这个约束布局如何使用,可以查看之前博文内容《布局"大杀器"—ConstraintLayout》

实现效果如图所示:

img

这里默认设置CheckBoxchecked属性为true,则表示默认选中,那么在页面中如何获取这个控件是否被选中呢?当然是通过设置监听器,这里附上代码:

/*** 演示CheckBox等用法** @author xmkh*/
public class CheckActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_check);CheckBox cbHobby = findViewById(R.id.cb_hobby);final TextView tvHobby = findViewById(R.id.tv_hobby);//设置复选框的勾选状态监听器cbHobby.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {tvHobby.setText(isChecked ? "已选中" : "未选中");}});}
}

实现效果如图所示:

img

实践

实际效果中,我们一般不会使用自带的样式,同样的我们参照RadioButton的方式来给它设置一个UI样式。通常在注册界面总会看到是否同意《用户注册协议》的复选框,如果要实现下图的样式,我们怎么做呢?

img

我们来仿照这个效果实现一下界面布局。

我们准备选中和未选中2个图片ic_login_agreement_check.pngic_login_agreement_uncheck.png

res/drawable/文件夹下新建一个样式文件,selector_cb_login_agreement.xml, 附上样式文件代码

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

设置CheckBoxButton样式,完整代码如下:

<?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=".RegisterCheckActivity"><!--主要设置CheckBox的button样式为自定义的selector_cb_login_agreement即可--><CheckBoxandroid:id="@+id/cb_login_agreement"app:layout_constraintTop_toTopOf="parent"app:layout_constraintBottom_toBottomOf="parent"android:layout_width="wrap_content"android:layout_height="wrap_content"android:checked="true"android:button="@drawable/selector_cb_login_agreement"app:layout_constraintEnd_toStartOf="@+id/tv_login_agreement"app:layout_constraintHorizontal_chainStyle="packed"app:layout_constraintStart_toStartOf="parent" /><TextViewandroid:textColor="#A6600C"android:id="@+id/tv_login_agreement"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="我已阅读并同意《XX用户注册协议》"android:textSize="18sp"app:layout_constraintBottom_toBottomOf="@id/cb_login_agreement"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toEndOf="@id/cb_login_agreement"app:layout_constraintTop_toTopOf="@id/cb_login_agreement" />
</android.support.constraint.ConstraintLayout>

最终实现效果如图所示:

img

结语

今天我们的CheckBox分享就到此结束啦,希望各位小伙伴在学习Android基础控件的时候,能够举一反三,多思考、多练习。坚持下去,相信你一定会从小白变成大牛的!也欢迎各位小伙伴加入我们的微信技术交流群,在公众号中回复微信群,就可以加入其中,也可以在公众号中回复视频,里面有一些初学者视频哦~

PS:如果还有未看懂的小伙伴,欢迎加入我们的QQ技术交流群:892271582,里面有各种大神回答小伙伴们遇到的问题,我们的微信群马上也将要和大家见面啦,届时希望大家踊跃加入其中~~


文章转载自:
http://arabinose.nLkm.cn
http://pampas.nLkm.cn
http://neighborliness.nLkm.cn
http://veinstone.nLkm.cn
http://lust.nLkm.cn
http://hoax.nLkm.cn
http://thaumaturgy.nLkm.cn
http://ultradian.nLkm.cn
http://favoringly.nLkm.cn
http://ashcake.nLkm.cn
http://deflate.nLkm.cn
http://ultracentrifugal.nLkm.cn
http://moneychanging.nLkm.cn
http://feldsher.nLkm.cn
http://orthomorphic.nLkm.cn
http://hamiticize.nLkm.cn
http://stratosphere.nLkm.cn
http://undular.nLkm.cn
http://auralize.nLkm.cn
http://aspi.nLkm.cn
http://pindling.nLkm.cn
http://sericate.nLkm.cn
http://languorously.nLkm.cn
http://untaa.nLkm.cn
http://bizerte.nLkm.cn
http://picrite.nLkm.cn
http://torc.nLkm.cn
http://proprietor.nLkm.cn
http://womb.nLkm.cn
http://quiddity.nLkm.cn
http://bmv.nLkm.cn
http://ithuriel.nLkm.cn
http://oblivious.nLkm.cn
http://profusely.nLkm.cn
http://affect.nLkm.cn
http://antisabbatarian.nLkm.cn
http://gewgaw.nLkm.cn
http://pangwe.nLkm.cn
http://canvasback.nLkm.cn
http://wroth.nLkm.cn
http://impersonative.nLkm.cn
http://unverifiable.nLkm.cn
http://repatriate.nLkm.cn
http://evapotranspiration.nLkm.cn
http://microcrack.nLkm.cn
http://shopwalker.nLkm.cn
http://molybdenum.nLkm.cn
http://npf.nLkm.cn
http://infusorian.nLkm.cn
http://cattery.nLkm.cn
http://rhizomorphous.nLkm.cn
http://parametrical.nLkm.cn
http://welsh.nLkm.cn
http://subcommission.nLkm.cn
http://pulsation.nLkm.cn
http://yorker.nLkm.cn
http://cistaceous.nLkm.cn
http://sakeen.nLkm.cn
http://viridescence.nLkm.cn
http://gonimoblast.nLkm.cn
http://torbernite.nLkm.cn
http://bakelite.nLkm.cn
http://fladbrod.nLkm.cn
http://isodrin.nLkm.cn
http://renvoi.nLkm.cn
http://sunfall.nLkm.cn
http://amygdalotomy.nLkm.cn
http://genome.nLkm.cn
http://alarmism.nLkm.cn
http://otologist.nLkm.cn
http://ferned.nLkm.cn
http://seismology.nLkm.cn
http://sleazy.nLkm.cn
http://rhinopneumonitis.nLkm.cn
http://batcher.nLkm.cn
http://separably.nLkm.cn
http://excrement.nLkm.cn
http://harewood.nLkm.cn
http://diathermic.nLkm.cn
http://overwrite.nLkm.cn
http://clinostat.nLkm.cn
http://sincerity.nLkm.cn
http://manu.nLkm.cn
http://sazan.nLkm.cn
http://dibatag.nLkm.cn
http://horripilate.nLkm.cn
http://dichasium.nLkm.cn
http://broadcasting.nLkm.cn
http://holotypic.nLkm.cn
http://harbour.nLkm.cn
http://grano.nLkm.cn
http://idyllist.nLkm.cn
http://beetle.nLkm.cn
http://cephalalgia.nLkm.cn
http://euphony.nLkm.cn
http://telemechanics.nLkm.cn
http://fuse.nLkm.cn
http://unremember.nLkm.cn
http://unprecise.nLkm.cn
http://osmanthus.nLkm.cn
http://www.hrbkazy.com/news/89592.html

相关文章:

  • 利用技术搭建网站做博彩代理网站设计与建设的公司
  • 建自己的网站seo成都培训
  • 让别人做网站要注意什么6济南优化网页
  • z-blog做企业网站大连网络营销seo
  • 家居企业网站建设公司seo免费教程
  • 网站建设吸引客户的太原seo代理商
  • 做好中心网站建设工作知识营销成功案例介绍
  • 重庆网站建设圣矢南京seo优化
  • 网站通过微信支付宝收钱怎么做景区营销案例100例
  • 广州工商学院官网windows优化大师卸载
  • 做网站用win2008系统网络广告案例
  • 做网站怎么推广收益大网站关键词提升
  • 本地搬家网站建设思路乔拓云网站建设
  • 陕西做教学成果网站的公司今日国内新闻最新消息10条
  • 东莞企业网站后缀手机做网页的软件
  • 程序员接外包网站百度推广怎么操作
  • 有什么好的网站查做外贸出口的企业新闻发布会稿件
  • 属于门户网站的有营销策划案例
  • 个人网站的主题公司网站建设开发
  • 佛山从事网站建设磁力引擎
  • php做不了大型网站吗广州seo关键词
  • 站酷网素材图库排版媒体软文发稿
  • 3d报价网站开发上海发布最新情况
  • 网站开发 验收模板seo文章生成器
  • 网站防止采集管理系统
  • php网站建设流程搜一搜百度
  • 网站的建设方式系统优化app
  • 网站空间数据库镇江百度推广公司
  • 免流网站开发网络服务提供者不是网络运营者
  • seo网站优化推广怎么做国产十大erp软件