android小笔记
2014-07-07 15:55
387 查看
android实现测试网络是否连通代码:调用系统ConnectivityManager cm = (ConnectivityManager)
this.getSystemService(CONNECTIVITY_SERVICE);,通过这个方法进行测试
android显示html文本:
html += "我的主页:http://www.zuji365.net
";
html += "我的Email:113605829@qq.com
";
html += "我的电话:13450233156
";
CharSequence text = Html.fromHtml(html);
TextView tv2 = (TextView)this.findViewById(R.id.textView2);
tv2.setText(text);//显示html文本
tv2.setMovementMethod(LinkMovementMethod.getInstance());//表示激活超链接
添加QQ表情,图片实例
![](https://img-blog.csdn.net/20140707155413734?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzk5NjAwMg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
输入提醒功能
![](https://img-blog.csdn.net/20140707160216109?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzk5NjAwMg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
this.getSystemService(CONNECTIVITY_SERVICE);,通过这个方法进行测试
ConnectivityManager cm = (ConnectivityManager) this.getSystemService(CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if(null!=netInfo && netInfo.isAvailable()){ Toast.makeText(this, "网络处于连通状态", Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(this, "网络不通,请检查网络状况", Toast.LENGTH_SHORT).show(); }
android显示html文本:
//普通文本 TextView tv1 = (TextView)this.findViewById(R.id.textView1); tv1.setTextColor(Color.BLUE); tv1.setBackgroundColor(Color.RED); tv1.setTextSize(30); //html文本 String html = "div文本" ;
html += "我的主页:http://www.zuji365.net
";
html += "我的Email:113605829@qq.com
";
html += "我的电话:13450233156
";
CharSequence text = Html.fromHtml(html);
TextView tv2 = (TextView)this.findViewById(R.id.textView2);
tv2.setText(text);//显示html文本
tv2.setMovementMethod(LinkMovementMethod.getInstance());//表示激活超链接
添加QQ表情,图片实例
package com.tocean.android02; import android.app.Activity; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.text.Spannable; import android.text.SpannableString; import android.text.style.ImageSpan; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; /** * 讲解EditText * * @author Administrator * */ public class Test05Activity extends Activity implements OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 使用一个全新的布局文件 this.setContentView(R.layout.test05_activity); et3 = (EditText) this.findViewById(R.id.et3); Button bq1 = (Button) this.findViewById(R.id.bq1); bq1.setOnClickListener(this); } private EditText et3; @Override public void onClick(View v) { // 构造一个可扩展的文本,可以添加表情 SpannableString ss = new SpannableString("[face]"); Drawable dr = v.getBackground();// 获得按钮的背景图片 dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight()); // 构造图片文本 ImageSpan is = new ImageSpan(dr, ImageSpan.ALIGN_BASELINE); //把上面的[face]占位符替换成图片文本 ss.setSpan(is, 0, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); int currentPostion = et3.getSelectionStart();//得到光标所处的位置 et3.getText().insert(currentPostion, ss); } }
输入提醒功能
package com.tocean.android02; import android.app.Activity; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.text.Spannable; import android.text.SpannableString; import android.text.style.ImageSpan; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.EditText; import android.widget.MultiAutoCompleteTextView; /** * 讲解EditText * * @author Administrator * */ public class Test06Activity extends Activity { private static String[] countries = { "China", "Japan", "England", "Google", "Huawei", "Xiaomi", "Good" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 使用一个全新的布局文件 this.setContentView(R.layout.test06_activity); //创建适配器(用到系统自动的一些图片和布局) ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, countries); AutoCompleteTextView actv = (AutoCompleteTextView)this.findViewById(R.id.actv); MultiAutoCompleteTextView mactv = (MultiAutoCompleteTextView)this.findViewById(R.id.mactv); //设置适配器 actv.setAdapter(adapter); mactv.setAdapter(adapter); mactv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); } }
相关文章推荐
- Android IMF学习笔记一
- Android笔记:GridView与ImageView
- Android(OPhone) 学习笔记 - HelloWorld资源
- Android(OPhone) 学习笔记 - 界面设计工具
- Android(OPhone) 学习笔记 - Intent和Activity
- Android Cupcake源码编译笔记
- Android(OPhone) 学习笔记 - 资源的访问和配置
- Android(OPhone) 学习笔记 - Mail API 的使用
- Android(OPhone) 学习笔记 - 布局
- Android 开发笔记
- Android笔记之二:改进的NotePad Demo
- Android原生(Native)C开发之七:libjpeg移植笔记
- Android(OPhone) 学习笔记 - HelloWorld工程简介
- Android IMF 学习笔记三
- Android 学习笔记(一)——开发环境搭建
- Android笔记-What is Android
- Android IMF学习笔记二
- Android(OPhone) 学习笔记 - 代码基础
- Android(OPhone) 学习笔记 - 菜单使用
- Android(OPhone) 学习笔记 - Hierarchy Viewer