2013-07-23 4 views
2

Есть ли способ изменить цвет синей линии под заголовком в диалоговом окне на цвет как желтый или оранжевый? Я пробовал:Изменить цвет синей линии под заголовком в диалоговом окне

  1. Изменение темы для AlertDialogs вручную
  2. Использование project: android-styled-dialogs библиотеки
  3. подклассов DialogPreference и добавление customTitleView с оранжевым Drawable, что это 2dp широкий в onPrepareDialogBuilder(Builder builder). (См. 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-color-of-the-line-under), который имеет хороший ответ – Geobits

+0

Уже пробовал это и решение Джозефа Эрла. Не работает. –

ответ

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> 

 Смежные вопросы

  • Нет связанных вопросов^_^