1、设置文字的超级链接,代码如下:
// 超级链接 TextView tv = (TextView) findViewById(R.id.cctvex); tv.setText("Please visit my website, http://bashenmail.iteye.com or email me at [email protected]."); 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);
//多个自动填充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());
<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"/>