2012-04-19 12 views
5

私はAlertDialogを持っており、これはカスタムダイアログビューを使用しています。カスタムタイトルビューのアイデアは十分にシンプルに見えますが、カスタムタイトルの周りに黒い境界線があり、取り除くことはできません。上辺、左辺、右辺には1ピクセルの境界線があり、下辺には約5ピクセルの境界線があります。AlertDialogカスタムタイトルに黒い境界線があります

Javaでダイアログを作成:

View titleView = inflater.inflate(R.layout.part_list_item, parent, false); 
((TextView) titleView.findViewById(R.id.partName)).setText(titleText); 
AlertDialog productDialog = new AlertDialog.Builder(getContext()) 
    .setCustomTitle(titleView) 
    .setAdapter(adapter, doNothingClickListener) 
    .create(); 

カスタムタイトルビューのレイアウト、part_list_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#ff0000" 
    android:id="@+id/partName" 
    android:layout_marginLeft="6dip" 
    android:textAppearance="?android:attr/textAppearanceLargeInverse" 
    /> 

私が見る何を:

screenshot broken

私が見たいもの:

screenshot fixed

+0

がTextViewのに必要な相対的なレイアウトと影でパディングですか..? – ngesh

+1

@sandy公正な質問。私はこれらのビットを削除しましたが、結果は同じですが、下の黒の境界線がより大きくなった点が異なります。 –

+0

XMLを拡張するときに 'attachToRoot'をtrueに設定しようとしてください。 – dreamtale

答えて

0

アラートにタイトルが付いている場合、アンドロイドによって作成された結果です。スクリーンショットの表示から、アラートの「ボディ」もカスタム・ビューであり、アラート・メッセージのプロパティではありません。

結果を得る最も簡単な方法は、アラートのカスタム表示にタイトルレイアウトを追加することです。

例:bodyView.addview(titleView);アラートのあなたの体の上にタイトルレイアウトを追加

View titleView = inflater.inflate(R.layout.part_list_item, parent, false); 

View bodyView = .... 
bodyView.addview(titleView); 
((TextView) itleView.findViewById(R.id.partName)).setText(titleText); 

AlertDialog productDialog = new AlertDialog.Builder(getContext()); 
productDialog.setView(bodyView); 
... 

productDialog.create(); 

そして、productDialog.setView(bodyView);はアラートのボディとしてカスタムビューを設定します。

+1

あなたのアプローチは、 'AlertDialog'をドロップしてカスタムの' Dialog'を利用する利点はありますか?私にとっては、AlertDialogの使用のポイントは、既にタイトルと、私が簡単に記入できるボディがあるということです。 –

+0

"body"ビューにtitleViewを追加することを提案しています。国境の問題を解決します。境界線はタイトルとメッセージの間にデフォルトで設定されているためです! –

3

これを試してみてください:

LayoutInflater inflater = (LayoutInflater)yourClass.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View titleView = inflater.inflate(R.layout.custom_dialog, null); 

((TextView) titleView.findViewById(R.id.partName)).setText("Your Title"); 
alert1.setCustomTitle(titleView); 
関連する問題