您的位置:首页 > 移动开发 > Android开发

android 常用代码

2012-04-22 18:08 225 查看
// 新建一个toast对象
private Toast toast;

public void showMsg(String arg) {
if (toast == null) {
toast = Toast.makeText(this, arg, Toast.LENGTH_SHORT);
} else {
toast.cancel();
toast.setText(arg);
}
toast.show();
}


res/drawable目录下面建立一个设置圆角边框参数的xml文件,如下:

corner_round.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<solid android:color="#FFCC33" />

<corners android:radius="10dp" />

</shape>


调用:android:background="@drawable/corner_round"

/**
* 获取当前日期
*/

protected String getNowTime() {
String nowTime = new SimpleDateFormat("yyyy年MM月dd日").format(new Date());
return nowTime;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: