android之各種佈局控件和對話框

6、

   1.默認效果

   Toast.makeText(getApplicationContext(), "默認Toast樣式",
    Toast.LENGTH_SHORT).show();

   2.自定義顯示位置效果

   toast = Toast.makeText(getApplicationContext(),
    "自定義位置Toast", Toast.LENGTH_LONG);
  toast.setGravity(Gravity.CENTER, 0, 0);
  toast.show();

   3.帶圖片效果

   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();


   4.完全自定義效果

   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.其他線程

   new Thread(new Runnable() {
   public void run() {
    showToast();
   }
  }).start();


    public void showToast() {
     handler.post(new Runnable() {

      @Override
      public void run() {
       Toast.makeText(getApplicationContext(), "我來自其他線程!",
         Toast.LENGTH_SHORT).show();

      }
     });
    }

       來自:http://www.cnblogs.com/salam/archive/2010/11/10/1873654.html

5、Android開發之ExpandableListView

http://www.cdtarena.com/gpx/201207/4304.html

4、

TextView tv=new TextView(this);

tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下劃線
       tv.setText("使用代碼實現下劃線樣式");
       tv.setTextColor(Color.WHITE);

在xml文件中使用android:textStyle="bold" 可以將英文設置成粗體,但是不能將中文設置成粗體,將中文設置成粗體的方法是:
TextView tv = (TextView)findViewById(R.id.TextView01);
TextPaint tp = tv.getPaint();
tp.setFakeBoldText(true);
其他還有:
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24f);//設置成24sp  
textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));//可能中文加粗無效
textView.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC));//可能中文無效
textView.setText(Html.fromHtml("<u>"+texts+"</u>"));//下劃線
textView.setTypeface(Typeface.MONOSPACE,Typeface.ITALIC);//斜體,中文有效
textView.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG );//中間加橫線
textView.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );//底部加橫線



promotionLinkText = (TextView) this .findViewById(R.id. text_promotion_link );
中間加橫線
promotionLinkText .getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG );
底部加橫線:
promotionLinkText .getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );

textView1.getPaint().setAntiAlias(true);// 抗鋸齒


textAppearanceButton/textAppearanceInverse/textAppearanceLarge/textAppearanceLargeInverse/textAppearanceMedium/textAppearanceMediumInverse/textAppearanceSmall/textAppearanceSmallInverse
textView.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG ); //下劃線
textView.getPaint().setAntiAlias(true);//抗鋸齒
textview.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG); //中劃線
setFlags(Paint. STRIKE_THRU_TEXT_FLAG|Paint.ANTI_ALIAS_FLAG);  // 設置中劃線並加清晰
textView.getPaint().setFlags(0);  // 取消設置的的劃線



原文:http://blog.csdn.net/caiyunfreedom/article/details/6763834


3、對話框大合集

http://bbs.51cto.com/viewthread.php?tid=878105

Android自定義對話框(Dialog)位置,大小

package angel.devil;

import android.app.Activity;

import android.app.Dialog;

import android.os.Bundle;

import android.view.Gravity;

import android.view.Window;

import android.view.WindowManager;

public class DialogDemoActivity extends Activity {

   /** Called when the activity is first created. */

   @Override

   public void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.main);


       Dialog dialog = new Dialog(this);


       // setContentView可以設置爲一個View也可以簡單地指定資源ID

       // LayoutInflater

       // li=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);

       // View v=li.inflate(R.layout.dialog_layout, null);

       // dialog.setContentView(v);

       dialog.setContentView(R.layout.dialog_layout);


       dialog.setTitle("Custom Dialog");

       /*

        * 獲取聖誕框的窗口對象及參數對象以修改對話框的佈局設置,

        * 可以直接調用getWindow(),表示獲得這個Activity的Window

        * 對象,這樣這可以以同樣的方式改變這個Activity的屬性.

        */

       Window dialogWindow = dialog.getWindow();

       WindowManager.LayoutParams lp = dialogWindow.getAttributes();

       dialogWindow.setGravity(Gravity.LEFT | Gravity.TOP);

       /*

        * lp.x與lp.y表示相對於原始位置的偏移.

        * 當參數值包含Gravity.LEFT時,對話框出現在左邊,所以lp.x就表示相對左邊的偏移,負值忽略.

        * 當參數值包含Gravity.RIGHT時,對話框出現在右邊,所以lp.x就表示相對右邊的偏移,負值忽略.

        * 當參數值包含Gravity.TOP時,對話框出現在上邊,所以lp.y就表示相對上邊的偏移,負值忽略.

        * 當參數值包含Gravity.BOTTOM時,對話框出現在下邊,所以lp.y就表示相對下邊的偏移,負值忽略.

        * 當參數值包含Gravity.CENTER_HORIZONTAL時

        * ,對話框水平居中,所以lp.x就表示在水平居中的位置移動lp.x像素,正值向右移動,負值向左移動.

        * 當參數值包含Gravity.CENTER_VERTICAL時

        * ,對話框垂直居中,所以lp.y就表示在垂直居中的位置移動lp.y像素,正值向右移動,負值向左移動.

        * gravity的默認值爲Gravity.CENTER,即Gravity.CENTER_HORIZONTAL |

        * Gravity.CENTER_VERTICAL.

        *

        * 本來setGravity的參數值爲Gravity.LEFT | Gravity.TOP時對話框應出現在程序的左上角,但在

        * 我手機上測試時發現距左邊與上邊都有一小段距離,而且垂直座標把程序標題欄也計算在內了,

        * Gravity.LEFT, Gravity.TOP, Gravity.BOTTOM與Gravity.RIGHT都是如此,據邊界有一小段距離

        */

       lp.x = 100; // 新位置X座標

       lp.y = 100; // 新位置Y座標

       lp.width = 300; // 寬度

       lp.height = 300; // 高度

       lp.alpha = 0.7f; // 透明度


       // 當Window的Attributes改變時系統會調用此函數,可以直接調用以應用上面對窗口參數的更改,也可以用setAttributes

       // dialog.onWindowAttributesChanged(lp);

       dialogWindow.setAttributes(lp);

       /*

        * 將對話框的大小按屏幕大小的百分比設置

        */

//        WindowManager m = getWindowManager();

//        Display d = m.getDefaultDisplay(); // 獲取屏幕寬、高用

//        WindowManager.LayoutParams p = getWindow().getAttributes(); // 獲取對話框當前的參數值

//        p.height = (int) (d.getHeight() * 0.6); // 高度設置爲屏幕的0.6

//        p.width = (int) (d.getWidth() * 0.65); // 寬度設置爲屏幕的0.95

//        dialogWindow.setAttributes(p);

       dialog.show();


   }

}



2、多式樣ProgressBar

http://www.eoeandroid.com/thread-1081-1-1.html

1、EditText控件

屬性:android:inputType有如下值設置:

none、

text、

textCapCharacters字母大小、

textCapWords單詞首字母大小、

textCapSentences僅第一個字母大小、

textAutoCorrect、textAutoComplete自動完成、

textMultiLine多行輸入、

textImeMultiLine輸入法多行(如果支持)、

textNoSuggestions不提示、

textEmailAddress電子郵件地址、

textEmailSubject郵件主題、

textShortMessage短信息(會多一個表情按鈕出來)

textLongMessage長訊息

textPersonName人名

textPostalAddress地址

textPassword密碼

textVisiblePassword可見密碼

textWebEditText作爲網頁表單的文本

textFilte文本篩選過濾

textPhonetic拼音輸入

numberSigned有符號數字格式

numberDecimal可帶小數點的浮點格式

phone電話號碼

datetime時間日期

date日期

time時間。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章