2013-07-23 3 views
2

DialogPreference의 제목 아래에있는 파란색 선의 색상을 노란색 또는 주황색으로 변경하는 방법이 있습니까? 나는 시도했다 :dialogpreference의 제목보기에서 청색 선 색상 변경

  1. project: android-styled-dialogs 라이브러리
  2. 서브 클래스 DialogPreference을 사용하여 수동으로
  3. AlertDialogs의 테마를 변경하고 onPrepareDialogBuilder(Builder builder)에 넓은 2DP의 오렌지 당김으로 customTitleView를 추가. (android Theme.Holo.Dialog changing blue lines to orange 참조)

이러한 시도는 성공하지 못했습니다. 누구나이 경험을 갖고 해결책을 찾았습니까?

+0

중복 가능성 (http://stackoverflow.com/questions/14439538/how-can-i-change- the-color-of-alertdialog-title-and-the-line-under), 좋은 대답을 가지고 있습니다 – Geobits

+0

이미 저와 Joseph Earl의 해결책을 시도했습니다. 작동하지 않습니다. –

답변

0

나는 알아 냈지만 그 해킹 된 솔루션입니다. DialogPreferences의 경우 AlertDialog.Builder 메서드는 showDialog()를 호출 할 때까지 호출되지 않습니다 (here 참조).

것을 아는 here에서 솔루션을 수정, 우리는 Window.FEATURE_NO_TITLE 플래그 제목을 없애와 제목이 우리 자신의 XML을 팽창하고 우리 자신의 수평 분할 내장 INT 수 있습니다

@Override 
    protected void showDialog(Bundle state) { 
     Context context = getContext();   
     AlertDialog.Builder mBuilder = new AlertDialog.Builder(context); 
     View view = LayoutInflater.from(context).inflate(R.layout.pref_dialog_about_title, null); 

     onBindDialogView(view); 
     mBuilder.setView(view); 
     onPrepareDialogBuilder(mBuilder); 

//  getPreferenceManager().registerOnActivityDestroyListener(); 

     // Create the dialog 
     final Dialog dialog = mBuilder.create(); 
     dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     if (state != null) { 
      dialog.onRestoreInstanceState(state); 
     } 

     dialog.setOnDismissListener(this); 
     dialog.show(); 

     Button neutralButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEUTRAL); 
     FontChanger.getInstance(getContext()).changeFont(neutralButton); 
     neutralButton.setTextColor(mColorOrangeEnabled); 
     neutralButton.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.ab_background_gradient_bottom)); 
    } 

여기서 onBindDialogView(View view)은 TextViews (제목 및 메시지)를 찾고 초기화합니다. onPrepareDialogBuilder()은 setNeutralButton (...)을 호출하기 만합니다.

pref_dialog_about_title.xml :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
    <LinearLayout 
     android:id="@+id/title_template" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:gravity="center_vertical" 
     android:background="@drawable/ab_background_gradient_top"> 
     <TextView 
      android:id="@+id/alertTitle" 
      style="?android:attr/textAppearanceLarge" 
      android:layout_marginTop="6dip" 
      android:layout_marginBottom="9dip" 
      android:layout_marginLeft="10dip" 
      android:layout_marginRight="10dip" 
      android:singleLine="true" 
      android:ellipsize="end" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"/> 
    </LinearLayout> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/border"> 

      <TextView 
       android:id="@+id/author" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true"/> 
      <TextView 
       android:id="@+id/btag" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/author" 
       android:layout_centerHorizontal="true"/> 

     </RelativeLayout> 
</LinearLayout> 

ab_background_gradient_top [이]의

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <!-- Bottom Line --> 
    <item> 
     <shape android:shape="rectangle"> 
      <solid android:color="@color/orange" /> 
     </shape> 
    </item> 

    <!-- Color of your action bar --> 
    <item android:bottom="2dip"> 
     <shape android:shape="rectangle"> 
      <gradient 
      android:angle="90" 
      android:centerColor="#3b0808" 
      android:endColor="#570b0b" 
      android:startColor="#1d0404" 
      android:type="linear" /> 

      <corners 
       android:radius="0dp"/> 
     </shape> 
    </item> 
</layer-list> 
관련 문제