Search code examples
androidandroid-alertdialogappcompatactivity

android AllertDialog doesn't have margin - What can cause this? maybe style issue?


I want to show an AlertDialog in the onCreate function of my AppCompatActivity and for some reason it doesn't have margins around it. See the image:

dialog without margin

Here is my code:

@Override
protected void onCreate(Bundle savedInstanceState){
 super.onCreate(savedInstanceState);

 //These are just some setters in the company code
 MyApplication.setActivity(this); 
 setTheme(R.style.AppTheme);
 setContentView(R.layout.activity_splash_screen);
 Intent intent = getIntent();
 String action = intent.getAction();
 if(action != null && action.compareTo(Intent.ACTION_VIEW) == 0){
     mHasContent = true;
     mContentUri = intent.getData();
 }else{
     mHasContent = false;
 }
 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

 initViews();

 AlertDialog.Builder builder = new AlertDialog.Builder(this);
 builder.setTitle("title");
 builder.setMessage("message");
 builder.create().show();
}

I have no idea what is causes the problem, the dialog is showing correctly at other places in my code.
(I have tried to put it into onResume and it's not working eather. I want to show it only when the activity created, that's why I am trying to use onCreate.)

Can my custom AppTheme cause the problem? If you think so I attach my relevant part of my styles.xml:

...
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
...
<style name="AppTheme" parent="AppBaseTheme">

    <item name="android:windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>

    <item name="toolbarStyle">@style/Toolbar</item>

    <item name="android:windowAnimationStyle">@style/WindowAnimationTransition</item>
    ...
</style>
...

I have tried to create a new project and put all the upper code in it (styles.xml and all the others) and I cannot reproduce the bug. What else can cause the problem?

Where can be the problem? Can anyone help?

I also have an application class with overrided onCreate() function and tried remove those function calls also but nothing changed. Is there other places in android which can impact this behaviour? I don't know the whole code, because it's a company app, so maybe some other overriden method or something?


Solution

  • I have removed this line from the activity in the manifest file and it solved my problem:

    android:theme="@style/SplashScreen"
    

    I don't know what caused it, so if anybody can explain it to me I would really appreciate it!