2015-12-14 6 views
4

У меня есть класс, который расширяет EditTextPreference и я использую его в своей компоновке, такие как:Как изменить размер текста сообщения о предпочтении диалога?

<com.app.MyEditTextPreference 
     android:key="@string/key" 
     android:title="@string/title" 
     android:summary="@string/summary" 
     android:dialogTitle="@string/title" 
     android:dialogMessage="@string/message" 
     android:layout="@layout/preference_edittext"/> 

Мое приложение тема наследует от Theme.AppCompat.Light.DarkActionBar и я изменил значения размеров текста:

<style name="TextAppearance.Small"> 
    <item name="android:textSize">18sp</item> <!-- was 14sp --> 
</style> 

Однако, когда отображается диалог предпочтений, размер сообщения отличается от того, который я определил в моем стиле.

Итак, как правильно установить размер текста диалогового сообщения?

EDIT

Я скопировал диалоговое раскладку из SDK:

<LinearLayout 
    android:id="@+android:id/edittext_container" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="20dp" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@android:id/message" 
     android:layout_marginBottom="48dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingStart="4dp" 
     android:paddingEnd="4dp" 
     android:textColor="?android:attr/textColorSecondary" 
     style="@style/TextAppearance.Small" /> 

</LinearLayout> 

Однако я получаю ошибку построения Resource is not public на линии android:id="@+android:id/edittext_container".

И если я изменю его на "@*android:id/edittext_container", текст редактирования больше не отображается.

Есть ли простой способ просто изменить текст сообщения?

ответ

0

я, наконец, удалось изменить текст сообщения размер по:

а) Изменение идентификатора LinearLayout: @+id/edittext_container и

б) Добавление следующий код в мой класс расширения EditTextPreference:

@Override 
protected void onAddEditTextToDialogView(View dialogView, EditText editText) { 
    ViewGroup container = (ViewGroup) dialogView 
      .findViewById(R.id.edittext_container); 

    if (container != null) { 
     container.addView(editText, ViewGroup.LayoutParams.MATCH_PARENT, 
       ViewGroup.LayoutParams.WRAP_CONTENT); 
    } 
} 

Это прекрасно работает и, очевидно, действительный ответ, однако более простым решением было бы просто изменить текст сообщения размер через themeing.

0

Сначала создайте новое имя xml-файла cus.xml в папке макета. ему необходимо установить представление для диалога во время выполнения.

<?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="match_parent"> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Enter Name :" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textSize="18dp" /> 


<EditText 
    android:id="@+id/editText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:textSize="18dp" /> 

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="New Button" 
    android:textSize="18dp" /> 

Как нужно диалог: вот диалог код:

Dialog d=new Dialog(getActivity()); 
       d.setTitle("Image Title"); 
       d.setContentView(R.layout.cus); 
       d.show();