做下记录,每次遇到的问题和解决方法,备忘。
1.去掉标题栏
android:theme="@android:style/Theme.NoTitleBar"
2.弹出警告框
AlertDialog.Builder builder= new AlertDialog.Builder(this);
builder.setTitle("测试");
builder.setMessage("点击测试成功");
builder.setPositiveButton("确认", null);
builder.create().show();
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setResult(RESULT_OK);//确定按钮事件
finish();
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//取消按钮事件
}
})
3.用户名和密码自动补全
http://lib.open-open.com/view/open1333356387467.html
4.toast介绍
和Dialog不一样的是,Toast是没有焦点的,而且Toast显示的时间有限,过一定的时间就会自动消失。
一般的
Toast.makeText(getApplicationContext(), "默认Toast样式",Toast.LENGTH_SHORT).show();
带位置的
toast = Toast.makeText(getApplicationContext(),"自定义位置Toast", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
带图片的
toast = Toast.makeText(getApplicationContext(),
"带图片的Toast", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout toastView = (LinearLayout) toast.getView();
ImageView imageCodeProject = new ImageView(getApplicationContext());
imageCodeProject.setImageResource(R.drawable.icon);
toastView.addView(imageCodeProject, 0);
toast.show();
自定义
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom,
(ViewGroup) findViewById(R.id.llToast));
ImageView image = (ImageView) layout
.findViewById(R.id.tvImageToast);
image.setImageResource(R.drawable.icon);
TextView title = (TextView) layout.findViewById(R.id.tvTitleToast);
title.setText("Attention");
TextView text = (TextView) layout.findViewById(R.id.tvTextToast);
text.setText("完全自定义Toast");
toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.RIGHT | Gravity.TOP, 12, 40);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
5.带链接的textview
1.xml中加入
TextView myTextView=(TextView)findViewById(R.id.textView2);
myTextView.setText("www.baidu.com");
Xml中加入android:autoLink="all|web"
2.
此时一定要把
这句 android:autoLink="all|web"去掉
myTextView.setText(Html.fromHtml("" +
"<a href=\"http://www.google.com\">点我吧点我吧</a> " ));
myTextView.setMovementMethod(LinkMovementMethod.getInstance());
3.
改变显示效果
//创建一个 SpannableString对象
SpannableString sp = new SpannableString("hgkgkjgjgkjg ");
//设置超链接
sp.setSpan(new URLSpan("http://www.baidu.com"), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//SpannableString对象设置给TextView
myTextView.setText(sp);
//设置TextView可点击
myTextView.setMovementMethod(LinkMovementMethod.getInstance());