安卓学习笔记之三

跑马灯的实现

1、在layout中添加属性

android:ellopsize="marquee"-----当文字过长时,该控件如何显示

                             start---省略号在开头

                             end---省略号在结尾

                             middle---省略号在中间

                             marquee---以跑马灯的形式显示

android:focusable="true"-----允许该button获取焦点,但buttton在触摸屏下无法获取焦点

android:focusableInTouchMode="true"-----不用捞取焦点,就触发事件。也就是説一运行,就触点该事件

android:singleLine="true"

2、在src中创建一个类,继承TextView,实现三个构造函数,重写isFocuse方法

右击鼠标-source-Generate Constructor From Superclass可以自动创建所有构造方法

public class marqquee extends TextView{

	public marqquee(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public marqquee(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	public marqquee(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}
	public boolean isFocuse(){
		return true;
	}

}

3、在将TextView的名字改为包名+类名


AutoCompleteTextView

功能实现:动态匹配输入的内容

独特属性:android:completion Threshold(门槛)=“2”----设置输入 多少字符时自动匹配

1、初始化控件

acText=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);

2、需要一个适配器

ArrayAdapter<String>adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,res);
ArrayAdapter<String>是个泛型,指定了此集合中只能存放String类型的数据
3、初始化数据源

private String[]res={"beijing1","bejing2","beijing3","shanghai1","shanghai2"};
4、将adapter与当前AutoCompleteTextView绑定

acText.setAdapter(adapter);
5、在控件设置属性
 android:completionThreshold="2"


MultiAutoCompleteTextView
功能:我支持选择多个值,分别用分隔符分开,并且在每个值选中的时候再次输入值时会自动匹配
独特属性:android:completionThreshold=“2”

                  mcText.setTokenizer(new MultiAutCompleteTextView.CommaTokenizer())---设置逗号分隔符

                  tokenizer为分词器的意思

方法与AutoCompleteTextView相同,只是多了最后一步设置分隔符

1、初始化控件

2、需要一个适配器

3、初始化数据源

4、将adapter与当前AutoCompleteTextView绑定

5、设置分隔符

macText.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
setTokenize()是设置分隔符的方法


ToggleButton
ToggleButton有两种状态:选中与未选中状态,并且需要为不同的状态设置不同的显示文本 、
属性:android:checked="true"(默认状态为false)
           android:textOff="Off"
           android:textOn="On"
MainActivity要实现OnCheckedChangeListener接口
当触发了第一段程序,第二段程序会响应
bt.setOnCheckedChangeListener(this);
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		ima.setBackgroundResource(isChecked?R.drawable.on:R.drawable.off);
	}
buttonView代表被点击控件本身
isChecked代表被点击的控件状态
setBackgroundResource()方法可以设置背景图片
步骤:
1、初始化控件
2、设置监听器


CheckBox
特有属性:android:checked="false"---是否被选中(默认状态为false)
                  android:text="男"---显示文本内容
步骤:初始化checkboox
           通过设置checkbox的setOnCheckedChangeListener()监听事件来判断checkbox是否被选中
           通过onCheckedChanged()来监听当前的checkbox是否被选中





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值