Android开发-控件详解

TextView

TextView继承了View,他还是EditText和Button两个UI组件的父类。

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <TextView
            android:layout_x="120dp"
            android:layout_y="200dp"
            android:id="@+id/textview1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="120dp"
            android:layout_weight="1"
            android:text="我爱你Android"
            android:textColor="@color/black"
            android:textSize="16sp" />

</AbsoluteLayout>

在这里插入图片描述

EditView

EditView(输入框)与TextView相似, 许多的XML属性可以公用,与TextView最大的区别就是EditView可以接受用户的输入。

使用android:hint来提示用户当前文本框要输入的内容是什么。

使用android:inputType属性来设置输入的类型

<EditText
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_y="50dp"
        android:layout_x="70dp"
        android:hint="请输入密码"
        android:textColor="@android:color/darker_gray"
        android:textSize="16sp"
        android:inputType="numberPassword" />

在这里插入图片描述

自定义样式

custom_edittext_background.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="#FFFFFFFF"/>
    <corners android:radius="3dip"/>
    <!-- 圆角-->
    <corners android:radius="5dp" />
    <!--描边-->
    <stroke
        android:width="2dip"
        android:color="@android:color/holo_blue_light" />

</shape>

<EditText
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_y="50dp"
        android:layout_x="70dp"
        android:hint="请输入密码"
        android:background="@drawable/custom_edittext_background"
        android:textColor="@android:color/darker_gray"
        android:textSize="16sp"
        android:inputType="numberPassword"
        />

在这里插入图片描述

Button

Button(按钮)继承了textView,它主要是UI界面上生成一个按钮,用户可以单机按钮,并且能为按钮添加onClick事件即的单击事件。

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_y="200dp"
        android:layout_x="100dp"
        android:id="@+id/button1"
        android:textSize="18dp"
        android:text="按钮"/>

ImageView

<ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="204dp"
        android:layout_y="109dp"
        android:src="@mipmap/ic_launcher_round" />

    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_x="0dp"
        android:layout_y="194dp"
        android:src="@mipmap/ic_launcher" />

在这里插入图片描述

RadioButton&CheckBox

RadioButton(单选按钮)&CheckBox(复选框),都是继承自Button类,需要和RadioGroup配合使用

<RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_x="0dp"
        android:layout_y="304dp">

            <RadioButton
                android:id="@+id/radioButton2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="" />

            <RadioButton
                android:id="@+id/radioButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="" />
    </RadioGroup>

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_y="400dp">
            <CheckBox
                android:id="@+id/checkbox"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_x="0dp"
                android:layout_y="422dp"
                android:text="NBA" />
            <CheckBox
                android:id="@+id/checkbox1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_x="0dp"
                android:layout_y="422dp"
                android:text="CBA" />
            <CheckBox
                android:id="@+id/checkbox2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_x="0dp"
                android:layout_y="422dp"
                android:text="NBL" />
            <CheckBox
                android:id="@+id/checkbox3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_x="0dp"
                android:layout_y="422dp"
                android:text="NCAA" />
    </RadioGroup>

在这里插入图片描述

ProgressBar

ProgressBar(进度条)

<ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_x="0dp"
        android:layout_y="497dp"/>

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_x="0dp"
        android:layout_y="570dp"
        android:layout_marginTop="30dp"
        android:progress="50"
        android:background="@android:color/holo_green_light"/>

在这里插入图片描述

SeekBar(拖动条)

<SeekBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/seekBar"
        android:layout_marginTop="20dp"
        android:background="@android:color/holo_green_light"/>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值