UI组件

TextView

属性设置

android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:id="@+id/autotx"

        

注意:setText()或setTextColor()方法的参数是一个int值还是一个资源地址

android:autoLink

    <TextView

        android:id="@+id/tvWebUrl"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:autoLink="web" />

    <TextView

        android:id="@+id/tvEmail"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:autoLink="email" />

    <TextView

        android:id="@+id/tvPhone"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:autoLink="phone" />

    <TextView

        android:id="@+id/tvMap"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:autoLink="map" />

    <TextView

        android:id="@+id/tvAll"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:autoLink="all"

        android:text="你好,很高兴认识你,我的博客:http://blog.csdn.net/jiahui524。 手机号码:15580974038.邮箱:272570596@qq.com" />

    <TextView

        android:id="@+id/tvHtml"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content" />

    <TextView

        android:id="@+id/tvHtml1"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:text="@string/link_text_manual" />

    private void findViews(){

     TextView tvWebUrl = (TextView)findViewById(R.id.tvWebUrl);

     tvWebUrl.setText("网易:http://www.163.com");

    

     TextView tvEmail,tvPhone, tvMap ,tvHtml;

    

     tvEmail = (TextView) this.findViewById(R.id.tvEmail);

     tvPhone =  (TextView) this.findViewById(R.id.tvPhone);

     tvMap = (TextView) this.findViewById(R.id.tvMap);

     tvHtml = (TextView)this.findViewById(R.id.tvHtml);

    

     tvEmail.setText("我的邮箱:drinkeye@163.com");

     tvPhone.setText("我的电话:500000");

    

     tvHtml.setText(Html.fromHtml("<font size='33' color='#333333'><i></i></font>京天<b></b>/n <br/>" +

     "<a href='http://www.163.com'>163</a>"));

    }

<string name="link_text_manual">

作者博客:

<a href="http://nokiaguy.blogjava.net">

http://nokiaguy.blogjava.net

</a>

</string>

注意:

android:autoLink=”email” :会出现unsupported action,可能是模拟器bug,须探究

另外使用Html.fromHtml时,超链接只具备外观,不能跳转

带边框的TextView

自定义带边框的TextView

package cn.class3g.activity;

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.Paint;

import android.util.AttributeSet;

import android.widget.TextView;

public class BorderTextView extends TextView {

public BorderTextView(Context context, AttributeSet attr) {

super(context,attr);

}

public void onDraw(Canvas canvas) {

super.onDraw(canvas);

Paint paint = new Paint();

paint.setColor(android.graphics.Color.GREEN);

canvas.drawLine(0, 0, this.getWidth() - 1, 0, paint);

canvas.drawLine(0, 0, 0, this.getHeight() - 1, paint);

canvas.drawLine(this.getWidth() - 1, 0, this.getWidth() - 1,

this.getHeight() - 1, paint);

canvas.drawLine(0, this.getHeight() - 1, this.getWidth() - 1,

this.getHeight() - 1, paint);

}

}

    <cn.class3g.activity.BorderTextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:gravity="center"

        android:padding="30dp"

        android:text="xxxxxxxxxxxxx"

        />

9-patch工具的使用

    <TextView

        android:id="@+id/tvBorder"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="@string/link_text_manual"

        android:textColor="#00FF00"

        android:background="@drawable/back" />

 1).什么是9patch

它是一个对png图片做处理的一个工具,能够为我们生成一个"*.9.png"的图片;

  2).何为"*.9.png"?

所谓"*.9.png"这是Android os里所支持的一种特殊的图片格式,用它可以实现部分拉伸;这种图片是经过9patch“进行特殊处理过的,如果不处理的话,直接用PNG图就会有失真,拉伸不正常的现象出现

EditText

基本属性的设置

输入特定字符

    <EditText

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:password="true"

        android:digits="01234" />

    <EditText

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:digits="abcd" />

    <EditText

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:inputType="number" />

    <EditText

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:inputType="textEmailAddress" />

    <EditText

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:numeric="decimal|signed" />

EditText中回车键的使用

EditText对象的注册OnKeyListener事件,实现onKey()方法

    <EditText

        android:id="@+id/text1"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:text="text1" />

    <Button

        android:id="@+id/button1"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:visibility="gone"

        android:text="Button" />

et.setOnKeyListener(this);

public boolean onKey(View view, int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_ENTER) {

btn.setText(et.getText());

et.setVisibility(View.GONE);

btn.setVisibility(View.VISIBLE);

}

return true;

}

习题:请实现点击button返回初始状态界面

自动完成输入内容的组件

l AutoCompleteTextView

l MultiCompleteTextView

    <AutoCompleteTextView 

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:id="@+id/autotx"

        />

    

    <MultiAutoCompleteTextView 

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:id="@+id/mautotx"

        />

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.hide);

btn = (Button) this.findViewById(R.id.button1);

et = (EditText) this.findViewById(R.id.text1);

et.setOnKeyListener(this);

autotx = (AutoCompleteTextView) this.findViewById(R.id.autotx);

String[] s={"a","abc","ab","b","bc","bdad"};

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,s);

autotx.setAdapter(adapter);

mautotx = (MultiAutoCompleteTextView) this.findViewById(R.id.mautotx);

mautotx.setAdapter(adapter);

mautotx.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值