基本控件使用

来源:互联网 发布:js 鼠标自动隐藏 编辑:程序博客网 时间:2024/06/04 22:02

一、TextView和EditText

<!--     wrap_content:包裹实际文本内容     match_parent:当前控件铺满父类容器     fill_parent:当前控件铺满父类容器          TextView常用属性     android:id ==控件id     android:layout_width==控件的宽度     android:layout_height==控件的高度     android:text==文本内容     android:textSize==文本颜色     android:background==控件背景     EditText常用属性     TextView 属相+     android:hint==输入提示文本     android:inputType==输入文本类型     -->    <EditText        android:id="@+id/textView2"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:hint=""        android:inputType=""        android:text="@string/hello_world" /> <TextView        android:id="@+id/textView2x"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/hello_world" />

通过id获得控件

tv=(TextView)this.findViewById(R.id.textView2x)

设置字体颜色

tv.setText("设置内容");

tv.setTextColor(Color.RED)

android:inputType="phone"为设置输入格式为拨号键盘

二、ImageView

<!-- android:src==图片路径  @drawable/abc_ab_bottom_solid_dark_holo" android:background ==可以设置图片和颜色 @drawable/abc_ab_bottom_solid_dark_holo 和#dddddd   --><ImageView     android:src="@drawable/abc_ab_bottom_solid_dark_holo"    android:background="#ffffff"    />
三、Button 和IMageButton



0 0