8.
7.
// double click to exit
private long lastBackPressedTime;
@Override
public void onBackPressed() {
if(System.currentTimeMillis() - lastBackPressedTime < 2000L) {
super.onBackPressed();
} else {
lastBackPressedTime = System.currentTimeMillis();
Toast.makeText(this, R.string.exit_toast, Toast.LENGTH_SHORT).show();
return;
}
}
6.
private Dialog showFontSizeDialog() {
final String[] sizes = {"24", "28", "32", "36", "40"};
AlertDialog.Builder dialog = new AlertDialog.Builder(mActivity.getAndroidContext());
dialog.setTitle(R.string.pref_video_settings_subtitle_fontsize_dialogtitle);
dialog.setItems(sizes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
int clickedInt = Integer.valueOf(sizes[arg1]);
SharedPreferences.Editor editor0 = mPrefs.edit();
editor0.putString("pref_video_settings_subtitle_fontsize_key", String.valueOf(clickedInt));
editor0.commit();
itemClicked.setTitle(clickedInt + " (choose subtitle font size)");
Toast.makeText(mActivity.getAndroidContext(), "you chosed the font size of " + clickedInt,
Toast.LENGTH_SHORT).show();
}
});
return dialog.show();
}
// end
5.
mSubtitleEnabled = (mSubtitleEnabled ? false : true);
SharedPreferences.Editor editor1 = mPrefs.edit();
editor1.putBoolean("pref_video_settings_subtitle_key", mSubtitleEnabled);
editor1.commit();
editText1 =(EditText) DialogView.findViewById(R.id.editText1);
SharedPreferences sp = Context.getSharedPreferences("SP", MODE_PRIVATE);
//存入数据
Editor editor = sp.edit();
editor.putString("STRING_KEY", "string");
editor.putInt("INT_KEY", 0);
editor.putBoolean("BOOLEAN_KEY", true);
editor.commit();
4. some xml attribute strangers:
- android:textSize="20.0sp" android:layout_margin="5.0dip" //remember the unit
- android:textColor="#ff000000" //black
<ImageButton android:src="@drawable/management_add" /> //styles.xml <style name="CustomStyle"> <item>... - <EditText style="@style/MainText"/>
- LinearLayout 滚动效果 将其放在
- <ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:fadingEdge="vertical">
<LinearLayout
android:id="@+id/hottopics"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:padding="10dip"
android:scrollbars="vertical">
</LinearLayout>
</ScrollView> -
3.运用系统电话,短信程序
- Dial:
- if(phone_number.equals("")) {
- Toast.makeText(MainActivity.this, R.string.str_warning_phone_null, Toast.LENGTH_LONG).show();
- } else {
- Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone_number));
- MainActivity.this.startActivity(intent);
- }
- SMS:
- Intent smsIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + mEntry.getNO()));
startActivity(smsIntent);
2.去除标题栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// 去除标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
1.listview拖动时背景变黑的问题
方法:在ListView中添加一个属性,android:cacheColorHint="#00000000"