nikkorejz
@nikkorejz
Android developer

AlertDialog Android. Проблема с отображением dialog после применения темы, как можно исправить?

Есть Activity, в которой по нажатию на элемент меню выходит AlertDialog, но без кнопок. Однако, если в Dialog не применена тема, то он отображается нормально, но как только тема (@style/...) будет применена к Dialog, то по краям вылезает рамка. Как ее можно убрать?
...
switch (item.getItemId()) {
	case R.id.xxx:
		onOpenDialog(R.id.xxx);

        return true;
    }
	return true;
}

protected Dialog onOpenDialog(int id) {
	switch (id) {
	case R.id.xxx:
		LayoutInflater inflater = getLayoutInflater();
		View layout = inflater.inflate(R.layout.activity_xxx, (ViewGroup)findViewById(R.id.layout_xxx));
		Typeface key2 = Typeface.createFromAsset(getAssets(),   getString(R.string.font));
		TextView text = (TextView)layout.findViewById(R.id.text_xxx);
		TextView text1 = (TextView)layout.findViewById(R.id.main_yyy);
		text.setText("Текст");
		text1.setTypeface(key2);
		ImageView image = (ImageView) layout.findViewById(R.id.icon_xxx);
		image.setImageResource(R.drawable.ic_launcher);

        final CustomAlertDialog dialog = new CustomAlertDialog(MainActivity.this);
		dialog.setView(layout);
        dialog.setTitle(getString(R.string.xxx));
		dialog.setCancelable(true);
        dialog.show();
		    default:
			    return null;
    }

}
    public class CustomAlertDialog extends AlertDialog {

        public CustomAlertDialog(Context context) {
            super(context, R.style.CustomDialogAnimationTheme);
        }}
...

Вот styles.xml:
...
</style>
    <style name="CustomDialogAnimationTheme" parent="@android:style/Theme.Holo.Light.Dialog" >
        <item name="android:windowAnimationStyle">@style/CustomDialogAnim</item>

    </style>

    <style name="CustomDialogAnim" parent="@android:style/Animation.Dialog">
        <item name="android:windowEnterAnimation">@anim/dialog_enter</item>
        <item name="android:windowExitAnimation">@anim/dialog_exit</item>
    </style>


aec940e603b641b289436ab0f19bc93d.png
  • Вопрос задан
  • 2851 просмотр
Решения вопроса 1
nikkorejz
@nikkorejz Автор вопроса
Android developer
Я нашел решение:
...
protected void onOpenDialog(int id) {
	switch (id) {
	case R.id.ххх:

        final Dialog dialog = new Dialog(MainActivity.this);
        dialog.setTitle("Title");
        dialog.setContentView(R.layout.activity_[xxx);
        dialog.getWindow().getAttributes().windowAnimations = R.style.CustomDialogAnim;


        dialog.show();
    }

}
    public class CustomAlertDialog extends AlertDialog {

        public CustomAlertDialog(Context context) {
            super(context, R.style.CustomDialogAnimationTheme);
        }}
...
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы