Я хотел бы использовать настраиваемое диалоговое окно при нажатии кнопки «Редактировать текст на экране настроек».
Сначала я попробовал метод .setDialogLayoutResource
, но он применяется только для редактирования текста. Не применялся фон Диалога или Название Диалога.
Вторичный, я пробовал
@Override
public void onDisplayPreferenceDialog(Preference preference) {
super.onDisplayPreferenceDialog(preference);
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
builder.setTitle("Test");
builder.show();
}
в SettingsFragment extends PreferenceFragmentCompat
классе. однако созданное мной диалоговое окно появится, когда исходное диалоговое окно в тексте редактирования исчезнет.
В-третьих, я передумал, чтобы получить диалог, используя findViewById. Я сделал CustomPreferenceEditText класс расширяет EditTextPreference. И переопределить public void onBindViewHolder(PreferenceViewHolder holder)
и использовать метод
EditText editText = (EditText) holder.findViewById(android.R.id.edit);
Однако он вернул нулевое исключение. Но заголовок или резюме отлично работает.
Я предположил, что есть идентификатор, который может Доступ к заголовку диалога или фону диалога для исходного диалога из текста редактирования, такого как текст редактирования @android:id/edit
.
Я пытался исследовать, но не смог найти до сих пор. Если вы знаете какие-либо ссылки или идеи, пожалуйста, дайте мне знать.
Это пользовательский класс редактирования текста
public class CustomPreferenceEditText extends EditTextPreference {
public CustomPreferenceEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public CustomPreferenceEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public CustomPreferenceEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomPreferenceEditText(Context context) {
super(context);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
AssetManager assetManager = getContext().getAssets();
final Typeface dqfont = Typeface.createFromAsset(assetManager, "fonts/dqfont.ttf");
TextView titleView = (TextView) holder.findViewById(android.R.id.title);
TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
titleView.setTextColor(getContext().getResources().getColor(R.color.white));
titleView.setTypeface(dqfont);
summaryView.setTextColor(getContext().getResources().getColor(R.color.white));
summaryView.setTypeface(dqfont);
}
}
Редактировать
pic1
pic2