Android控件之TextView和EditText
TextView:显示文本框控件
EditText:输入文本框
TextView和EditText的常用属性
TextView控件的常用属性
android:id 控件的id
android:layout_width 控件的宽度
android:layout_height 控件的高度
android:text 文本内容
android:textSize 文本大小
android:textColor 文本颜色
android:background 控件背景
EditText的常用属性除了和TextView相同的这些常用属性外,还包括:
android:hint 输入提示文本
android:inputType 输入文本类型
在main_activity中插入TextView和EditText信息:

wrap_content:包裹实际文本内容
match_parent:当前控件铺满父类容器:2.3api之后添加的一个属性值
fill_parent:当前控件铺满父类容器:2.3api之前的一个属性值

TextView:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="姓名:" 
        android:textSize="28sp"
        android:textColor="#00FF00"
        />

EditText:

<EditText
        android:hint="请输入你的姓名"
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
<LinearLayout 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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.textviewedittext.MainActivity$PlaceholderFragment"
    android:orientation="horizontal"
    >
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="姓名:" 
        android:textSize="28sp"
        android:textColor="#00FF00"
        />

    <EditText
        android:hint="请输入你的姓名"
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >

        <requestFocus />
    </EditText>

</LinearLayout>
fragment_main.xml

相关文章:

  • 2022-12-23
  • 2021-08-07
  • 2021-05-11
  • 2022-02-17
  • 2021-06-15
  • 2022-12-23
  • 2021-09-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
相关资源
相似解决方案