2017-12-11 5 views
1

AlertDialogボックスのタイトルヘッダーを変更しようとしていますが、出力が私が求めていたものではありません。私はのstyles.xmlで次のスタイルを作成しています:AlertDialogのタイトルヘッダーを変更します

<style name="question_dialog" 
    parent="@android:style/Theme.Holo.Dialog"> 
    <item name="android:windowTitleStyle">@style/question_dialog_title</item> 
</style> 

<style name="question_dialog_title" parent="android:Widget.TextView"> 
<item name="android:background">#5cc5cc</item> 
<item name="android:textSize">21sp</item> 
<item name="android:textColor">#ffffff</item> 
</style> 

次のようにJavaのコードは次のとおりです。

new AlertDialog.Builder(this, 
R.style.question_dialog).setTitle("Assam Quiz"). 
setMessage("Hello world Hello world"). 
setPositiveButton("OK", (dialog, which) - > 
{dialog.dismisd(); 
}).show(); 
} 

AlertDialogイメージが装着されています。 enter image description hereスタイルのうち

+0

あなたのスタイル彼の事件。別のスタイルで試してください –

+0

アクションバーを非表示にしますか? – KeLiuyue

答えて

1

から私はあなたのダイアログが一番上になるようにタイトルを防止し、それに設定され、いくつかのヘッダのレイアウトを持っていると思うが、それはケースかある場合 - ダイアログヘッダーのためのあなたがすることができます簡単にset a custom titleそれだけにヘッダーのレイアウトを与え、そしてあなたは、ダイアログヘッダーのための完全な制御を持つことになります。

// creating the Dialog 
AlertDialog.Builder builder = new AlertDialog.Builder(context); 
// getting dialog context 
Context mContext = builder.getContext(); 
// building the inflater 
LayoutInflater mLayoutInflater = LayoutInflater.from(mContext); 
// inflate the dialog header layout 
View mView = mLayoutInflater.inflate(R.layout.simple_dialog_header, null); 
// get the TextView for the header (contained in the header layout) 
TextView mTextView = (TextView) mView.findViewById(R.id.title_text); 
// set the text for that TextView 
mTextView.setText(message); 
// set the custom header view for the dialog 
builder.setCustomTitle(mView); 
/* 
here you can set positive , negative ,neutral buttons 
or set the dialog message or any attribute you want 
*/ 
// finally, show the dialog 
builder.show(); 

とヘッダレイアウト(R.layout.simple_dialog_header)について:トンで問題を作成

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/primary" 
    android:orientation="vertical" 
    android:paddingBottom="15dp" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp" 
    android:paddingTop="15dp"> 

    <TextView 
     android:id="@+id/title_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:maxLines="1" 
     android:textAlignment="center" 
     android:textColor="@color/primary" 
     android:textSize="16sp" 
     android:textStyle="bold" /> 

</LinearLayout> 
+0

多くの多くのありがとう。これは私がまさに望んでいたものです。 – John

+0

あなたはあなたの問題を解決して嬉しいです:) –

関連する問題