Android 基本界面-文本编辑控件
7 1 TextViewhttp://www.apkbus.com/data/attachment/forum/201205/14/142141pq53pp2qnmnw5qsu.png
一般用来文本展示,继承自,在包中。
他的常用子类有。
常用属性设置:
android:text=“” 文字显示
android:autoLink=””链接类型。Web网址,email邮件,phone电话,map地图。Linkify。
链接状态时,Web情况可直接调用浏览器进行浏览。Email直接调用手机的Email软件,phone转到拨打电话页面。
2
http://www.apkbus.com/data/attachment/forum/201205/14/142205rewo5ixx5bxxkzbo.png
上面的图为AutoCompleteTextView和MultiAutoCompleteTextView
带提示的输入框,继承自,在包中。
和都是自动提示,一个是单选,一个多选。
常用属性设置:
输入几个字符时提示
就是一个带自动提示的,当输入字符时,会出现提示窗口,点击选择即可。首先在中定义一个,然后需要在设置数据源就可以了。的构造方法三个参数为:上下文的,每行的布局,数据源。
this.autoCompleteTextView = (AutoCompleteTextView) super.findViewById(R.id.autoCompleteTextView);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.arrayadapte_textview, CITY_NAMES);
this.autoCompleteTextView.setAdapter(arrayAdapter);和的类似,也是带有提示的输入框。区别在于可以连续提示,选择一个提示项后会自动添加一个分隔符,在输入时继续提示。则属于单选模式的。
使用时需要设置分隔符类其他与一样。
this.multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); 3 TextSwitcher
文字切换。继承自在包中。
使用方法设置动画。
例子,设置的动画,并使用数字时钟更改的字符串
public class SwitcherActivity extends Activity implements ViewSwitcher.ViewFactory, View.OnClickListener {
private Button buttonChangeText;
private TextSwitcher myTextSwitcher;
private DigitalClock myDigitalClock;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.switcher);
this.buttonChangeText = (Button) super.findViewById(R.id.buttonChangeText);
this.myTextSwitcher = (TextSwitcher) super.findViewById(R.id.myTextSwitcher);
this.myDigitalClock = (DigitalClock) super.findViewById(R.id.myDigitalClock);
this.buttonChangeText.setOnClickListener(this);
this.myTextSwitcher.setFactory(this);
this.myTextSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
this.myTextSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));
}
@Override
public View makeView() {
TextView textView = new TextView(this);
textView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
textView.setTextSize(36);
return textView;
}
@Override
public void onClick(View v) {
this.myDigitalClock.addTextChangedListener(textWatcher);
}
private android.text.TextWatcher textWatcher = new android.text.TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
SwitcherActivity.this.myTextSwitcher.setText(SwitcherActivity.this.myDigitalClock.getText());
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
};
}我们在来看看xml里的代码吧
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal">
<Button android:id="@+id/buttonChangeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始" />
<DigitalClock android:id="@+id/myDigitalClock"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="36dip"/>
<TextSwitcher android:id="@+id/myTextSwitcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>这个就是我们常说的android控件,新手们要好好的看哦,每一个成功的实例都是我们一点一点积累起来的。大家要是对这篇文章有什么问题,我们可以回帖交流。希望高手带带我,少让我走的弯路
页:
[1]