A
A
Artix2014-08-27 18:06:10
Android
Artix, 2014-08-27 18:06:10

AlertDialogAndroid. Problem with displaying dialog after applying a theme, how can I fix it?

There is an Activity in which, by clicking on a menu item, an AlertDialog appears, but without buttons. However, if no theme is applied to the Dialog, it displays normally, but as soon as the theme (@style/...) is applied to the Dialog, a border pops out around the edges. How can it be removed?

...
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);
        }}
...

Here is 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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artix, 2014-08-27
@nikkorejz

I found a solution:

...
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);
        }}
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question