android commonly used


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:

  1. android:textSize="20.0sp"      android:layout_margin="5.0dip"            //remember the unit
  2. android:textColor="#ff000000"                                                        //black
    <ImageButton android:src="@drawable/management_add" />            //styles.xml  <style name="CustomStyle"> <item>...
  3. <EditText style="@style/MainText"/>
  4. LinearLayout 滾動效果 將其放在
  5. <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.運用系統電話,短信程序

  1. Dial:
  2. if(phone_number.equals("")) {
  3.                     Toast.makeText(MainActivity.this, R.string.str_warning_phone_null, Toast.LENGTH_LONG).show();
  4.                 } else {
  5.                     Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone_number));
  6.                     MainActivity.this.startActivity(intent);
  7.                 }
  8. SMS:
  9. 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"

 

 

發佈了7 篇原創文章 · 獲贊 4 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章