當前位置:首頁 » 安卓系統 » android自定義對話框樣式

android自定義對話框樣式

發布時間: 2025-10-04 23:03:01

① 如何自定義ios多選對話框 android

Android自定義對話框的思路就是編寫對話框的布局文件xml,然後在對話框中顯示不同的控制項。以下以顯示文本控制項為例(ImageView等都可以顯示)。
1.布局文件connect_dlg.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="#ffffffff"
android:orientation="vertical"
android:id="@+id/llToast" >
<TextView
android:layout_height="wrap_content"
android:layout_margin="1dip"
android:textColor="#ffffffff"
android:layout_width="fill_parent"
android:gravity="center"
android:textSize="16sp"
android:background="#FF129de2"
android:id="@+id/tvTitleToast" />
<LinearLayout
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/llToastContent"
android:layout_marginLeft="1dip"
android:layout_marginRight="1dip"
android:layout_marginBottom="1dip"
android:layout_width="wrap_content"
android:padding="15dip"
android:background="#FFFFFFFF" >
<TextView
android:layout_height="wrap_content"
android:paddingRight="10dip"
android:paddingLeft="10dip"
android:layout_width="wrap_content"
android:gravity="center"
android:textSize="16sp"
android:textColor="#FFff6699"
android:id="@+id/tvTextToast" />
</LinearLayout>
<LinearLayout
android:id="@+id/MyLayout_ad2"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="40sp">
<com.tencent.exmobwin.banner.TAdView
android:id="@+id/adview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top|right" >
</com.tencent.exmobwin.banner.TAdView>
</LinearLayout>
</LinearLayout>
2.編寫顯示對話框函數。ShowConnectDialog(String textString)
private void ShowConnectDialog(String textString) {
LinearLayout loginLayout1 = (LinearLayout) getLayoutInflater().inflate(
R.layout.connect_dlg, null);
// adView.
TextView title = (TextView) loginLayout1
.findViewById(R.id.tvTitleToast);
title.setText("系統提示");
TextView text1 = (TextView) loginLayout1.findViewById(R.id.tvTextToast);
text1.setText(textString);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(loginLayout1);
builder.setPositiveButton("下載MobCtrl伺服器?", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//處理確定按鈕
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 處理取消按鈕
finish();
}
});
builder.create().show();
}
3.顯示對話框。在需要顯示的地方調用即可。
ShowConnectDialog("連接超時,請檢查伺服器是否開啟及IP地址是否輸入正確。確保電腦和手機連接在同一個網路內。");

② android如何創建帶3個按鈕的對話框

1.先在布局界面上,拖進來一個按鈕控制項,並設置顯示的文字,記得保存(Ctrl+S)

之後在代碼界面上定義該按鈕。

2.新建一個按鈕點擊的方法。
onClick(View v) :點擊之後的動作。

3.設置按鈕的點擊事件指向我們新建的點擊方法。
setOnClickListener:設置點擊之後觸發的動作。

4.在onClick里添加彈出對話框的代碼。
AlertDialog:一個對話框類。
MainActivity.this:對話框顯示的位置。
setTitle:設置標題。
setMessage:設置內容。
setPositiveButton:設置對話框的按鈕。
show():顯示對話框。

至此所有代碼已經完成,編譯並生成,在Android安卓虛擬機上顯示如下。

③ Android UI開發中,設置Activity的什麼屬性可以使Activity顯示為對話框樣式.

將activity設置成對話框樣式,只需在activity屬性裡面增加下面一句代碼:

④ 怎麼使用android軟體的搜索功能

當你需要在你的應用程序中提供搜索服務時,通過使用Android的搜索框架,應用程序將顯示一個自定義搜索對話框來處理用戶的搜索請求。通過一個簡單的搜索按鈕或從您的應用程序中調用API,搜索對話框就會顯示在屏幕的頂部,並會自動顯示應用程序圖標。

本文將教你如何為你的應用程序提供一個自定義搜索對話框。這樣做,給您的用戶提供一個標准化的搜索體驗,並能增加如語音搜索和搜索建議等功能。

基礎知識

Android的搜索框架將代您管理的搜索對話框,您不需要自己去開發一個搜索框,不需要擔心要把搜索框放什麼位置,也不需要擔心搜索框影響您當前的界面。所有的這些工作都由SearchManager類來為您處理(以下簡稱「搜索管理器」),它管理的Android搜索對話框的整個生命周期,並執行您的應用程序將發送的搜索請求,返回相應的搜索關鍵字。

當用戶執行一個搜索,搜索管理器將使用一個專門的Intent把搜索查詢的關鍵字傳給您在配置文件中配置的處理搜索結果的Activity。從本質上講,所有你需要的就是一個Activity來接收Intent,然後執行搜索,並給出結果。具體來說,你需要的做的事就包括以下內容:

一個搜索配置
我們用個XML配置文件來對搜索對話框進行配置,包括一些功能的配置,如文本框,設置語音搜索和搜索建議中顯示的提示文字等。

一個用來處理搜索請求的Activity
這個Activity用來接收搜索查詢的內容,然後搜索您的數據並顯示搜索結果。

一種用戶執行搜索的途徑
默認情況下,一旦你配置了一個可搜索的Activity,設備搜索鍵(如果有)將調用搜索對話框。然而,你應該始終提供另一種手段,讓用戶可以調用搜索對話框,如在選項菜單中的搜索按鈕或其他用戶界面上的按鈕,因為不是所有的設備提供一個專門的搜索鍵。

創建一個搜索對話框配置文件

搜索框配置文件是一個用來配置您的應用程序中搜索框的設置的XML文件,這個文件一般命名為searchable.xml,並且必須保存在項目的res/xml/目錄下。

配置文件的根節點必須為,可以有一個或多個屬性。

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

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

定義外觀

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

編寫對話框和 Builder 類


⑥ Android開發中,關於對話框中的圓形進度條和Layout的問題

首先解決問題一的問題:
你肯定使用了系統的 oncreateDialog 和 showdialog 方法了,所以 這個就會顯示一次 第二次不顯示了 , 你應該調用 dialog方法裡面的 show()方法 來顯示,這樣每次顯示那個progressbar都會在轉圈

問題二:
你說下面設置了一個白色背景,但是下面還是有個框,不過我有個疑問,如果你設置為白色背景,那麼你的轉條默認是白色的不就看不見了嗎?好了這個問題不糾結了!那個黑色的是邊框導致的,去掉邊框就行了

一般我們採用的是自定義dialog,也就是寫一個類來繼承dialog,這個時候的構造函數是這個:

public MyDialog(Context context, int theme) {
super(context, theme);
this.context = context;
init();
}

這個theme是什麼東西呢? 就是一個style樣式 如下:

<resources>    <style name="dialog" parent="@android:style/Theme.Dialog">        <item name="android:windowFrame">@null</item><!--邊框--        <item name="android:windowIsFloating">true</item><!--是否浮現在activity之上--      
<item name="android:windowIsTranslucent">false</item><!--半透明--        <item name="android:windowNoTitle">true</item><!--無標題--        <item name="android:windowBackground">@color/transparent</item><!--背景透明--        <item name="android:backgroundDimEnabled">false</item><!--模糊--    </style></resources> 

其他代碼:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Dialog dialog = new MyDialog(this, R.style.MyDialog);

android.view.WindowManager.LayoutParams pa3 = new android.view.WindowManager.LayoutParams();
pa3.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
pa3.width = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
pa3.x = 0;//x 起點
pa3.y = 0;//y起點
Window window = dialog.getWindow();
window.setAttributes(pa3);
dialog.show();
return super.onKeyDown(keyCode, event);
}
之所以android.view.WindowManager.LayoutParams我要這么寫,因為LayoutParams太多了,我害怕你找半天,兄弟對你夠好了吧!
要是選為精彩回答 那就謝謝你了!

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

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

⑧ android中的對話框怎麼寫

Activities提供了一種方便管理的創建、保存、回復的對話框機制,例如onCreateDialog(int),onPrepareDialog(int,Dialog),showDialog(int),dismissDialog(int)等方法,如果使用這些方法的話,Activity將通過getOwnerActivity()方法返回該Activity管理的對話框(dialog).

onCreateDialog(int):當你使用這個回調函數時,Android系統會有效的設置這個Activity為每個對話框的所有者,從而自動管理每個對話框的狀態並掛靠到Activity上。這樣,每個對話框繼承這個Activity的特定屬性。比如,當一個對話框打開時,菜單鍵顯示為這個Activity定義的選項菜單,音量鍵修改Activity使用的音頻流。

showDialog(int):當你想要顯示一個對話框時,調用showDialog(intid)方法並傳遞一個唯一標識這個對話框的整數。當對話框第一次被請求時,Android從你的Activity中調用onCreateDialog(intid),你應該在這里初始化這個對話框Dialog。這個回調方法被傳以和showDialog(intid)相同的ID。當你創建這個對話框後,在Activity的最後返回這個對象。

onPrepareDialog(int,Dialog):在對話框被顯示之前,Android還調用了可選的回調函數onPrepareDialog(intid,Dialog).如果你想在每一次對話框被打開時改變它的任何屬性,你可以定義這個方法。這個方法在每次打開對話框時被調用,而onCreateDialog(int)僅在對話框第一次打開時被調用。如果你不定義onPrepareDialog(),那麼這個對話框將保持和上次打開時一樣。這個方法也被傳遞以對話框的ID,和在onCreateDialog()中創建的對話框對象。

dismissDialog(int):當你准備關閉對話框時,你可以通過對這個對話框調用dismiss()來消除它。如果需要,你還可以從這個Activity中調用dismissDialog(intid)方法,這實際上將為你對這個對話框調用dismiss()方法。如果你想使用onCreateDialog(intid)方法來管理你對話框的狀態(就如同在前面的章節討論的那樣),然後每次你的對話框消除的時候,這個對話框對象的狀態將由該Activity保留。如果你決定不再需要這個對象或者清除該狀態是重要的,那麼你應該調用removeDialog(intid)。這將刪除任何內部對象引用而且如果這個對話框正在顯示,它將被消除。

下面是幾種對話框的效果

圖一:

圖1效果:該效果是當按返回按鈕時彈出一個提示,來確保無誤操作,採用常見的對話框樣式。


代碼:
創建對話框方法dialog()

protected void dialog() {
AlertDialog.Builder builder = new Builder(Main.this);
builder.setMessage("確認退出嗎?"); builder.setTitle("提示"); builder.setPositiveButton("確認", new OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); Main.this.finish();
}
}); builder.setNegativeButton("取消", new OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}); builder.create().show();
}

在onKeyDown(int keyCode, KeyEvent event)方法中調用此方法

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
dialog();
}
return false;
}

圖2效果:改變了對話框的圖表,添加了三個按鈕

Dialog dialog = new AlertDialog.Builder(this).setIcon(
android.R.drawable.btn_star).setTitle("喜好調查").setMessage(
"你喜歡李連傑的電影嗎?").setPositiveButton("很喜歡",
new OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(Main.this, "我很喜歡他的電影。",
Toast.LENGTH_LONG).show();
}
}).setNegativeButton("不喜歡", new OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(Main.this, "我不喜歡他的電影。", Toast.LENGTH_LONG)
.show();
}
}).setNeutralButton("一般", new OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(Main.this, "談不上喜歡不喜歡。", Toast.LENGTH_LONG)
.show();
}
}).create(); dialog.show();

圖3效果:信息內容是一個簡單的View類型

new AlertDialog.Builder(this).setTitle("請輸入").setIcon(
android.R.drawable.ic_dialog_info).setView(
new EditText(this)).setPositiveButton("確定", null)
.setNegativeButton("取消", null).show();

圖4效果:信息內容是一組單選框

new AlertDialog.Builder(this).setTitle("復選框").setMultiChoiceItems(
new String[] { "Item1", "Item2" }, null, null)
.setPositiveButton("確定", null)
.setNegativeButton("取消", null).show();

圖5效果:信息內容是一組多選框

new AlertDialog.Builder(this).setTitle("單選框").setIcon(
android.R.drawable.ic_dialog_info).setSingleChoiceItems(
new String[] { "Item1", "Item2" }, 0,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setNegativeButton("取消", null).show();

圖6效果:信息內容是一組簡單列表項

new AlertDialog.Builder(this).setTitle("列表框").setItems(
new String[] { "Item1", "Item2" }, null).setNegativeButton(
"確定", null).show();

圖7效果:信息內容是一個自定義的布局

1.布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:background="#ffffffff" android:orientation="horizontal"
android:id="@+id/dialog">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/tvname" android:text="姓名:" />
<EditText android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/etname" android:minWidth="100dip"/></LinearLayout>

2.調用代碼

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.dialog,
(ViewGroup) findViewById(R.id.dialog)); new AlertDialog.Builder(this).setTitle("自定義布局").setView(layout)
.setPositiveButton("確定", null)
.setNegativeButton("取消", null).show();

熱點內容
微信手勢密碼在哪裡改 發布:2025-10-05 00:22:07 瀏覽:101
linux編寫shell 發布:2025-10-05 00:21:11 瀏覽:423
琉璃神社的解壓碼 發布:2025-10-05 00:15:38 瀏覽:934
安卓為什麼越來越值錢 發布:2025-10-05 00:13:05 瀏覽:726
win2003配置php 發布:2025-10-05 00:09:05 瀏覽:81
編譯器如何將十進制轉為二進制 發布:2025-10-05 00:02:36 瀏覽:522
c語言arccos 發布:2025-10-05 00:02:32 瀏覽:995
編譯器如何區分成員函數 發布:2025-10-05 00:02:21 瀏覽:238
cpanelftp密碼 發布:2025-10-04 23:56:46 瀏覽:366
反編譯去除檢驗序列號 發布:2025-10-04 23:54:37 瀏覽:839