最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android編程自定義Dialog的方法分析

 更新時間:2017年03月04日 14:36:14   作者:aloxc  
這篇文章主要介紹了Android編程自定義Dialog的方法,結(jié)合實例形式分析了Android自定義Dialog的界面布局、功能實現(xiàn)及相關(guān)注意事項,需要的朋友可以參考下

本文實例講述了Android編程自定義Dialog的方法。分享給大家供大家參考,具體如下:

功能:

android 提供給我們的只有2種Dialog 即 AlertDialog & ProgressDialog 但是 Dialog 有其自身的特點:1. 不是 Activity 2. 開銷比 Activity 小得多

鑒于以上的優(yōu)點 我們就有定制自己Dialog 的需求

原理:

1. android 系統(tǒng)提供了一個class: Dialog. 而且你可以把自己的工作放在"protected void onCreate(Bundle savedInstanceState)" 在里面先調(diào)用系統(tǒng)的"super.onCreate(savedInstanceState)" 其就會保證調(diào)用這個method.

2. 至于 Dialog 界面的定制 可以寫一個xml 文件 然后 在 "void onCreate(Bundle)" 通過 "setContentView()" 來使之生效

3. Dialog 使用問題: 1. 彈出:show() 2. 取消:dismiss()

代碼:

1. 創(chuàng)建一個 Dialog:

public class CustomDialog extends Dialog {
  public CustomDialog(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
  }
  protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.custom_dialog);
    setTitle("Custom Dialog");
    TextView text = (TextView)findViewById(R.id.text);
    text.setText("Hello, this is a custom dialog!");
    ImageView image = (ImageView)findViewById(R.id.image);
    image.setImageResource(R.drawable.sepurple);
    Button buttonYes = (Button) findViewById(R.id.button_yes);
    buttonYes.setHeight(5);
    buttonYes.setOnClickListener(new Button.OnClickListener(){
      public void onClick(View v) {
        // TODO Auto-generated method stub
        dismiss();
      }
    });
    Button buttonNo = (Button) findViewById(R.id.button_no);
    buttonNo.setSingleLine(true);
    buttonNo.setOnClickListener(new Button.OnClickListener(){
      public void onClick(View v) {
        // TODO Auto-generated method stub
        dismiss();
      }
    });
  }
  //called when this dialog is dismissed
  protected void onStop() {
    Log.d("TAG","+++++++++++++++++++++++++++");
  }
}

2. Dialog 的使用:

public class CustomDialogUsage extends Activity {
  CustomDialog cd;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    cd = new CustomDialog(this);
    Button buttonYes = (Button) findViewById(R.id.main_button);
    buttonYes.setOnClickListener(new OnClickListener(){
      public void onClick(View v) {
        // TODO Auto-generated method stub
        cd.show();
      }
    });
  }
}

3. Dialog 的界面定制:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="10dp">
  <ImageView android:id="@+id/image" android:layout_width="wrap_content"
  android:layout_height="fill_parent" android:layout_marginRight="10dp"
  />
  <LinearLayout android:orientation="vertical"
  android:layout_width="fill_parent" android:layout_height="wrap_content"
  android:padding="5px">
    <TextView android:id="@+id/text" android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:textColor="#FFF" />
    <LinearLayout android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="5px">
      <Button android:id="@+id/button_yes"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text=" Yes " android:gravity="center"
      />
      <Button android:id="@+id/button_no"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text=" No " android:gravity="center"
      />
    </LinearLayout>
  </LinearLayout>
</LinearLayout>

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

  • 玩轉(zhuǎn)Kotlin 徹底弄懂Lambda和高階函數(shù)

    玩轉(zhuǎn)Kotlin 徹底弄懂Lambda和高階函數(shù)

    這篇文章主要幫助大家徹底弄懂Lambda和高階函數(shù),玩轉(zhuǎn)Kotlin,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Android原生視頻播放VideoView的使用

    Android原生視頻播放VideoView的使用

    這篇文章主要為大家詳細(xì)介紹了Android原生視頻播放VideoView的使用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • Android編程中的消息機制實例詳解

    Android編程中的消息機制實例詳解

    這篇文章主要介紹了Android編程中的消息機制,結(jié)合實例形式較為詳細(xì)的分析了Android中消息機制的原理,注意事項與相關(guān)使用技巧,需要的朋友可以參考下
    2016-01-01
  • Android  LayoutInflater加載布局詳解及實例代碼

    Android LayoutInflater加載布局詳解及實例代碼

    這篇文章主要介紹了Android LayoutInflater加載布局詳解及實例代碼的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • Android 動態(tài)的顯示時間

    Android 動態(tài)的顯示時間

    本文給大家分享一段代碼實現(xiàn)android動態(tài)顯示時間,代碼簡單易懂,非常不錯,具有參考借鑒價值,需要的朋友參考下吧
    2016-12-12
  • Android 使用Vitamio打造自己的萬能播放器(1)——準(zhǔn)備

    Android 使用Vitamio打造自己的萬能播放器(1)——準(zhǔn)備

    本文主要介紹Android Vitamio,在Android開發(fā)視頻播放器的時候,大家經(jīng)常會遇到系統(tǒng)版本和不同的Android手機不同導(dǎo)致開發(fā)的軟件不能完美適用,這里給大家介紹個播放器插件可以適應(yīng)所有Android設(shè)備
    2016-07-07
  • 安卓逆向案例分析之蟬媽媽sign破解

    安卓逆向案例分析之蟬媽媽sign破解

    這篇文章主要為大家介紹了安卓逆向案例分析蟬媽媽sign破解的方式講解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步
    2022-02-02
  • Android開發(fā)之merge結(jié)合include優(yōu)化布局

    Android開發(fā)之merge結(jié)合include優(yōu)化布局

    這篇文章主要為大家詳細(xì)介紹了Android開發(fā)之merge結(jié)合include優(yōu)化布局,感興趣的朋友可以參考一下
    2016-06-06
  • Android啟動相機拍照并返回圖片

    Android啟動相機拍照并返回圖片

    Android啟動相機拍照并返回圖片,事先定義拍照方法,在啟動拍照之前先判斷內(nèi)存是否可用,通過重寫onactivityresult()方法,獲取拍好的圖片。對下文感興趣的朋友可以參考下
    2015-10-10
  • 往Android系統(tǒng)中添加服務(wù)的方法教程

    往Android系統(tǒng)中添加服務(wù)的方法教程

    最近因為平臺升級,需要在系統(tǒng)中添加一些服務(wù),所以將整個過程總結(jié)一下,下面這篇文章主要給大家介紹了往Android系統(tǒng)中添加服務(wù)的方法教程,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-05-05

最新評論

赤城县| 唐海县| 凤翔县| 收藏| 仲巴县| 黄陵县| 江源县| 新津县| 沅江市| 霍林郭勒市| 临澧县| 洛阳市| 阿瓦提县| 浠水县| 盐亭县| 大埔县| 福贡县| 天津市| 康马县| 开封县| 德钦县| 屯昌县| 庆云县| 合阳县| 奉新县| 阿勒泰市| 扶沟县| 高清| 富裕县| 清远市| 黑水县| 什邡市| 黄平县| 仪陇县| 罗江县| 宜丰县| 郧西县| 定边县| 米林县| 汉源县| 麻阳|