Android开发须知的小知识


 1、设置文字的超级链接,代码如下:

// 超级链接
		TextView tv = (TextView) findViewById(R.id.cctvex);
		tv.setText("Please visit my website, http://bashenmail.iteye.com or email me at bashenmail@qq.com.");
		Linkify.addLinks(tv, Linkify.ALL);

   效果如下图:

 

 

  2、设置文本样式,代码如下:

 

// 文本样式
		EditText et = (EditText) findViewById(R.id.tv);
		et.setText("Styling the content of an editText dynamically");
		Spannable sp = et.getText();
		sp.setSpan(new BackgroundColorSpan(Color.RED), 0, 7,
				Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 0, 7,
				Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

  效果如下图:

  

 

 

 

 

 

 

3、单个自动填充 AutoComplete代码如下:

 

//单个自动填充 AutoComplete  
		AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.actv);
		ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
				android.R.layout.simple_dropdown_item_1line, new String[] {
						"English", "Hebrew", "Hindi", "Spanish", "German",
						"Greek" });
		actv.setAdapter(aa);

 

效果如图:

 4、多个自动填充,代码如下:

 

 //多个自动填充MultiAutoComplete
		MultiAutoCompleteTextView mactv = (MultiAutoCompleteTextView)findViewById(R.id.mactv);
		ArrayAdapter<String> aa2 = new ArrayAdapter<String>(this,
				android.R.layout.simple_dropdown_item_1line,new String[]{
				"English", "Hebrew", "Hindi", "Spanish", "German",
				"Greek" 
		});
		mactv.setAdapter(aa2);
		mactv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

 

效果如图:

 xml文件代码:

<TextView  
    android:id="@+id/cctvex"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    />
<EditText 
    android:id="@+id/tv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/> 

<AutoCompleteTextView 
    android:id="@+id/actv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>   
   
<MultiAutoCompleteTextView 
    android:id="@+id/mactv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/> 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值