Android自定義dialog簡單實(shí)現(xiàn)方法
本文實(shí)例講述了Android自定義dialog簡單實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.function_music);
// 實(shí)例化新的窗口
Window w = getWindow();
// 獲取默認(rèn)顯示數(shù)據(jù)
Display display = w.getWindowManager().getDefaultDisplay();
// 獲取窗口的背景圖片
Resources resources = musicActivity.getResources();
Drawable drawable = resources.getDrawable(R.drawable.operate_bg);
// 設(shè)置窗口的背景圖片
w.setBackgroundDrawable(drawable);
// 窗口的標(biāo)題為空
w.setTitle(null);
// 定義窗口的寬和高
int width = (int) (display.getWidth() * 0.8);
int height = (int) (display.getHeight() * 0.5);
// 設(shè)置窗口的大小
w.setLayout(width, height);
// 設(shè)置窗口的顯示位置
w.setGravity(Gravity.CENTER);
// 設(shè)置窗口的屬性
WindowManager.LayoutParams wl = w.getAttributes();
w.setAttributes(wl);
// 獲取控件
findView();
}
更多關(guān)于Android開發(fā)相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》
希望本文所述對大家Android程序設(shè)計有所幫助。
相關(guān)文章
Android實(shí)現(xiàn)開機(jī)自動啟動Service或app的方法
這篇文章主要介紹了Android實(shí)現(xiàn)開機(jī)自動啟動Service或app的方法,結(jié)合實(shí)例形式分析了Android開機(jī)自啟動程序的具體步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-07-07
Android后臺啟動Activity的實(shí)現(xiàn)示例
這篇文章主要介紹了Android后臺啟動Activity的實(shí)現(xiàn)示例,幫助大家更好的理解和學(xué)習(xí)使用Android開發(fā),感興趣的朋友可以了解下2021-04-04
Android BottomSheetDialog實(shí)現(xiàn)底部對話框的示例
這篇文章主要介紹了Android BottomSheetDialog實(shí)現(xiàn)底部對話框的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-06-06
Android編程實(shí)現(xiàn)EditText字?jǐn)?shù)監(jiān)聽并顯示的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)EditText字?jǐn)?shù)監(jiān)聽并顯示的方法,涉及Android EditText文本框事件監(jiān)聽與響應(yīng)相關(guān)操作技巧,需要的朋友可以參考下2017-02-02
Android App中使用SurfaceView制作多線程動畫的實(shí)例講解
這篇文章主要介紹了Android App中使用SurfaceView制作多線程動畫的實(shí)例講解,SurfaceView經(jīng)常被用來制作游戲中的動畫,不過同時要注意畫面閃爍的問題,需要的朋友可以參考下2016-04-04

