1、ProgressDialog的简单应用:
ProgressDialog dialog = ProgressDialog.show(this, "hello", "are you sure???");
new Thread(){
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dialog.dismiss();
};
}.start();
ps:Thread.sleep不能放在主线程,否则的话ProgressDialog将不会显示
2、AlertDialog的另一种应用:
代码实现:
array = getResources().getStringArray(R.array.you_choice);
new AlertDialog.Builder(this).setTitle("请选择").setItems(array, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).create().show();
定义array:res/values/Strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World!</string>
<string name="app_name">Android_SDK_Sample</string>
<array name="you_choice">
<item>牛肉</item>
<item>米饭</item>
<item>豆角</item>
</array>
</resources>
3、丰富界面显示,Theme的使用
setTheme(R.style.Theme_AlphaTheme);
setContentView(R.layout.ch3_19);
Theme_AlphaTheme定义在res/values/style.xml中
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="mystyle">
<item name="android:textSize">18sp</item>
<item name="android:textColor">#EC9237</item>
<item name="android:fromAlpha">0.0</item>
<item name="android:toAlpha">0.0</item>
</style>
<style name="Theme" parent="android:Theme">
</style>
<style name="Theme.AlphaTheme">
<item name="android:background">#aaff00ff</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorForeground">@drawable/blue</item>
<item name="android:colorBackground">@drawable/pink</item>
</style>
</resources>
4、代码片段:
设置EditText中的文字是明文还是密文显示。
//明文
et.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
//密文
et.setTransformationMethod(PasswordTransformationMethod.getInstance());
5、代码片段:一般我们在国际化的时候,需要改变当前系统的语系。程序实现如下:
Resources res = getResources();
Configuration conf = res.getConfiguration();
conf.locale = Locale.JAPAN;
DisplayMetrics dm = new DisplayMetrics();
res.updateConfiguration(conf, dm)
;