2013-07-23 17 views
8

アラートダイアログの背景を変更したいと思います。私はそうするように、次のコードピースを試してみました:Androidアラートダイアログの背景を変更する方法タイトル

<style name="Theme.AlertDialog" parent="@android:style/Theme.Holo.Light.Dialog"> 
     <item name="android:background">@android:color/transparent</item> 
     <item name="android:textColor">#659F26</item> 
     <item name="android:windowTitleStyle">@style/Theme.AlertDialog.Title</item> 
    </style> 

    <style name="Theme.AlertDialog.Title" parent="@android:style/TextAppearance.DialogWindowTitle"> 
     <item name="android:background">@drawable/cab_background_top_example</item> 
    </style> 

Javaコード:

ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.Theme_AlertDialog); 
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctw); 

alertDialogBuilder.setTitle(getResources().getString(R.string.confirmation)); 
alertDialogBuilder.setMessage(getResources().getString(R.string.msg));  
alertDialogBuilder.show(); 

私のアプリは、このようなダイアログ表示されています。私はそれを見てみたいしながら、

enter image description here

をlike:

enter image description here

私が間違っていることを提案してください。

+0

なぜダウン票を使いますの? – mudit

+0

私はちょうどあなたの質問から私の側から+1を私の問題を解決..... – duggu

答えて

6

使用このコードをダイアログを作成:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 

タイトルで行わ独自のレイアウトとして、多くのカスタマイズを作成し、その後、あなたのレイアウトを設定

dialog.setContentView(R.layout.yourlayout); 

注:使用

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); before  
dialog.setContentView(R.layout.yourlayout); 

それ以外の場合はエラーとなります。このライン使用では

+1

は、デフォルトのダイアログのレイアウトを変更してこれを行う方法があります。私はちょうどタイトルとあなたが提案している方法を変更したい、私は自分自身と他のいくつかのものをレイアウトする必要があります。 – mudit

+0

はい、あなたは多くのことをカスタマイズできます –

+2

私の質問:レイアウト全体を変えるスタイルを使ってこれを処理する方法はありますか? – mudit

0
ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.Theme_AlertDialog); 

代わりに "this" ActivityName.this

+1

これはOPの問題に対する解決策ではありません。 – laalto

関連する問題