導航:首頁 > 操作系統 > 自定義對話框樣式android

自定義對話框樣式android

發布時間:2022-07-11 16:27:01

android 的 AlertDialog 對話框樣式可以修改嗎

Android 提供了AlertDialog類可通過其內部類Builder輕松創建對話框窗口,但是沒法對這個對話框窗口進行定製,為了修改 AlertDialog 窗口顯示的外觀,解決的辦法就是創建一個指定的 AlertDialog 和 AlertDialog.Builder 類。

定義外觀

我們希望將上面默認的對話框外觀修改為如下圖所示的新對話框風格:

編寫對話框和 Builder 類


⑵ Android如何把QQ登錄界面和自定義對話框結合起來

1、在Android打開設置找到模擬器。
2、在模擬器中輸入qq賬號不輸入密碼,點擊登錄按鈕會顯示提醒對話框。
2、登陸qq後在對話框內輸入賬號和密碼,qq登錄的界面和自定義對話框就會結合起來。

⑶ android怎麼設置activity為對話框模式

將activity設置成對話框樣式,只需在activity屬性裡面增加下面一句代碼:
然後可以activity左邊增加一個小圖片,讓它更像dialog,代碼如下:
但是上面的設置往往還不能滿足實際需求,因為樣子、背景和一些屬性使用的默認的,下面使用style自定義一個,以後可以根據實際需要自行更改:

⑷ android怎麼實現自定義對話框的背景

1. 在res/values下創建兩個xml文件,一個為主體風格資源styles.xml一個為顏色資源colors.xml
styles.xml :

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name = "translucent" parent = "@android:style/Theme.Dialog">
<item name = "android:windowBackground">@color/translucent_background</item>
<item name = "android:windowIsTranslucent">true</item>
<item name = "android:windowNoTitle">true</item>
<item name ="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
</style>
</resources>

colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name = "translucent_background">#00000000</color>
</resources>
2. 在AndroidManifest.xml為Activity指定自定義的主題
<activity android:name = 「.right」 android:theme = 「@style/translucent」 />

3. 在顯示圖片的activity布局文件中加入圖片資源(設置layout的背景或者增加一個ImageView顯示圖片)
4.在Activity java文件right.java中關聯布局文件,然後運行Android工程到此activity.

安卓怎麼修改系統「DIALOG」風格

具體步驟如下:

1編寫一個文本樣式。

DIALOG的標題是一個textview,在sytles.xml中,添加如下代碼來設置你自己的文本樣式:

<style name="DialogWindowTitle">
<item name="android:textSize">22sp</item>
<item name="android:textColor">@color/font_dark_grey</item>
</style>

2設置對話框的標題主題。

上面的標題文本並不能直接設置為對話框的標題樣式。 我們還需要編寫一個表示標題的主題的style,在這里指定標題的文本樣式。代碼如下:

<style name="DialogWindowTitle.DeviceDefault">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">@style/DialogWindowTitle</item>
</style>

3設置對話框主題。

接下來,我們編寫我們的對話框主題,在這里指定標題的主題。由於一些屬性並不是public的,所以我們需要繼承自原來的某個style,代碼如下:

<!--Dialog主題-->
<style name="Theme.DeviceDefault.Dialog" parent="@android:style/Theme.DeviceDefault.Light.Dialog">
<item name="android:windowTitleStyle">@style/DialogWindowTitle.DeviceDefault</item>
</style>

4自定義App的主題。

接下來,我們需要在我們的App theme中指定我們的對話框使用這種主題,所以需要定義一個App theme。同樣由於App theme的許多屬性並不是public的(比如下面要提到的標題下面的那條藍線),所以我們要繼承自一個原生的style。這里我根據程序需要選擇了Theme.Holo.Light.NoActionBar,代碼如下:

<style name="ParkingTheme" parent="@android:style/Theme.Holo.Light.NoActionBar">
<item name="android:dialogTheme">@style/Theme.DeviceDefault.Dialog</item>
</style>

5指定App主題

我們需要在AndroidManifest.xml文件中,指定我們的app主題。這步很簡單,只需要在application標簽中指定android:theme的值即可,如下:

android:theme="@style/ParkingTheme"

6編寫AlertDialog主題。

我們無法直接繼承系統主題里的AlertDialog的style。如把parent指定為Theme.DeviceDefault.Dialog.Alert,Theme.Holo.Dialog.Alert,Theme.DeviceDefault.Light.Dialog.Alert或Theme.Holo.Light.Dialog.Alert,都會導致編譯不過。所以我們需要繼承自Dialog的style。在這里我以Theme.Holo.Light.Dialog為例,代碼如下:

<!--AlderDialog主題-->
<style name="Theme.DeviceDefault.Dialog.Alert" parent="@android:style/Theme.Holo.Light.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowTitleStyle">@style/DialogWindowTitle.DeviceDefault</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
</style>

7指定AlertDialog的主題。

我們需要在第4步所說的自定義的AppTheme中,添加一行代碼來指定要使用的AlertDialog的style,代碼如下:

<item name="android:alertDialogTheme">@style/Theme.DeviceDefault.Dialog.Alert</item>

8修改標題下面的藍色線。

表示這條藍色的線的叫做titleDivider,我們可以通過getResources()的API來獲取它的IP,然後設置顏色。代碼如下:

public static final void dialogTitleLineColor(Dialog dialog, int color) {
Context context = dialog.getContext();
int divierId = context.getResources().getIdentifier("android:id/titleDivider", null, null);
View divider = dialog.findViewById(divierId);
divider.setBackgroundColor(color);

這行代碼對於自定義的Dialog,可以在setContentView之後調用。但是對於AlertDialog,必須在show()方法被調用之後才可以去調用,否則會報錯。

⑹ android中怎麼設置一個日期的自定義對話框

在用戶點擊輸入框或者輸入框獲得焦點的時候彈出來DatePickerDialog,用戶點擊設定按鈕,將日期填寫到輸入框。
下面直接上代碼:

[html] view plain print?
<EditText
android:id="@+id/Birthday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:inputType="none"//不顯示系統輸入鍵盤
android:layout_weight="1" >
</EditText>

[java] view plain print?
birthday = (EditText)findViewById(R.id.Birthday);
birthday.setInputType(InputType.TYPE_NULL); <span style="font-family: Arial, Helvetica, sans-serif;">//不顯示系統輸入鍵盤</span>
birthday.setOnFocusChangeListener(new View.OnFocusChangeListener() {

@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if(hasFocus){
Calendar c = Calendar.getInstance();
new DatePickerDialog(ProfileActivity.this, new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
birthday.setText(year+"/"+(monthOfYear+1)+"/"+dayOfMonth);
}
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)).show();

}
}
});

birthday.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar c = Calendar.getInstance();
new DatePickerDialog(ProfileActivity.this, new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
birthday.setText(year+"/"+(monthOfYear+1)+"/"+dayOfMonth);
}
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)).show();

}
});

⑺ android怎樣自定義對話框給個源碼參考參考~

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.function_music);
// 實例化新的窗口
Window w = getWindow();
// 獲取默認顯示數據
Display display = w.getWindowManager().getDefaultDisplay();
// 獲取窗口的背景圖片
Resources resources = musicActivity.getResources();
Drawable drawable = resources.getDrawable(R.drawable.operate_bg);
// 設置窗口的背景圖片
w.setBackgroundDrawable(drawable);
// 窗口的標題為空
w.setTitle(null);
// 定義窗口的寬和高
int width = (int) (display.getWidth() * 0.8);
int height = (int) (display.getHeight() * 0.5);
// 設置窗口的大小
w.setLayout(width, height);
// 設置窗口的顯示位置
w.setGravity(Gravity.CENTER);
// 設置窗口的屬性
WindowManager.LayoutParams wl = w.getAttributes();
w.setAttributes(wl);
// 獲取控制項
findView();
}
參考資料:Android自定義控制項與自定義動畫實戰精講視頻課程【張科勇】

⑻ android開發中怎麼自定義一個復選對話框

1.首先在drawable文件夾中添加drawable文件checkbox_style.xml。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/checkbox_pressed" android:state_checked="true"/>

<item android:drawable="@drawable/checkbox_normal" android:state_checked="false"/>
<item android:drawable="@drawable/checkbox_normal"/>
</selector>
2.在values文件夾下的styles.xml文件中添加CustomCheckboxTheme樣式。
<style name="CustomCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox_style</item>
</style>
3.在布局文件中使用CustomCheckboxTheme樣式。
<CheckBox
android:id="@+id/select_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/CustomCheckboxTheme" />
使用到的圖片資源

checkbox_normal.png
checkbox_pressed.png

閱讀全文

與自定義對話框樣式android相關的資料

熱點內容
真實的幸福pdf 瀏覽:340
d盤php調用c盤的mysql 瀏覽:264
怎麼樣搭建源碼網站 瀏覽:427
新概念四冊pdf 瀏覽:361
怎麼下載悅虎檢測app 瀏覽:528
cad表達式命令 瀏覽:198
程序員去一個小公司值不值得 瀏覽:846
程序員做個程序多少錢 瀏覽:495
win10原始解壓軟體 瀏覽:319
阿里程序員的老家 瀏覽:258
量子加密銀行 瀏覽:193
命令方塊獲得指令手機 瀏覽:499
學習結束感言簡短程序員 瀏覽:398
android關機鬧鍾實現 瀏覽:968
滑鼠一鍵打開文件夾設置 瀏覽:161
程序員看過來我想靜靜搞笑視頻 瀏覽:370
curlphp爬蟲 瀏覽:874
python按日期循環 瀏覽:110
php三個等號 瀏覽:760
培訓班出來的程序員解決問題很差 瀏覽:963