android自定義彈出框樣式實現

2021-08-20 03:26:09 字數 2775 閱讀 9731

android自定義彈出框樣式實現

做專案時,感覺android自帶的彈出框樣式比較醜,很多應用都是自己做的彈出框,這裡也試著自己做了乙個。

廢話不說先上:

1.先自定義乙個彈出框的樣式

2.自己實現customdialog類,繼承自dialog,實現裡面方法,在裡面載入自定義樣式的彈出框;

3.使用時,與使用dialog一樣

<?xml version="1.0" encoding="utf-8"?>

<?xml version="1.0" encoding="utf-8"?>

package com.dyr.custom;

import android.content.context;

import android.content.dialoginte***ce;

import android.view.layoutinflater;

import android.view.view;

import android.view.viewgroup.layoutparams;

import android.widget.button;

import android.widget.linearlayout;

import android.widget.textview;

import com.dyr.view.r;

public class customdialog extends dialog

public customdialog(context context, int theme)

public static class builder

public builder setmessage(string message)

/*** set the dialog message from resource

* * @param title

* @return

*/public builder setmessage(int message)

/*** set the dialog title from resource

* * @param title

* @return

*/public builder settitle(int title)

/*** set the dialog title from string

* * @param title

* @return

*/public builder settitle(string title)

public builder setcontentview(view v)

/*** set the positive button resource and it's listener

* * @param positivebuttontext

* @return

*/public builder setpositivebutton(int positivebuttontext,

dialoginte***ce.onclicklistener listener)

public builder setpositivebutton(string positivebuttontext,

dialoginte***ce.onclicklistener listener)

public builder setnegativebutton(int negativebuttontext,

dialoginte***ce.onclicklistener listener)

public builder setnegativebutton(string negativebuttontext,

dialoginte***ce.onclicklistener listener)

public customdialog create()

});}

} else

// set the cancel button

if (negativebuttontext != null)

});}

} else

// set the content message

if (message != null) else if (contentview != null)

dialog.setcontentview(layout);

return dialog;

} }}

customdialog.builder builder = new customdialog.builder(this);

builder.setmessage("這個就是自定義的提示框");

builder.settitle("提示");

builder.setpositivebutton("確定", new dialoginte***ce.onclicklistener()

});builder.setnegativebutton("取消",

new android.content.dialoginte***ce.onclicklistener()

});builder.create().show();

至此,自定義彈出框已經完成,是不是感覺很簡單呢。

android自定義彈出框樣式實現

android自定義彈出框樣式實現

1.先自定義乙個彈出框的樣式 2.自己實現customdialog類,繼承自dialog,實現裡面方法,在裡面載入自定義樣式的彈出框 3.使用時,與使用dialog一樣 package com.jiayinlending.widget.dialog import android.content.co...

Android自定義彈出框AlertDialog

今天有空把自定義彈出框研究了一下,一直在用,都沒有仔細的看 今兒mark一下。先上個圖,做出來的效果 step 1 先自定義乙個顯示圖,我寫的xml檔案如下 這裡為了讓現實框變成圓角的,在linearlayout空間上加了乙個background,檔名是window bg,具體的圓角實現如下 這樣就...

Android自定義輸入框樣式

資料來自 菜鳥教程 自行編寫乙個shapedrawable的資源檔案!然後textview將blackgroung 設定為這個drawable資源即可!shapedrawable資源檔案的幾個節點以及屬性 需要改變游標的顏色 1 自定義bg cursor的drawable下xml檔案 2 在edit...