Customize Theme Programmactically Causes a Black Background

When I launch the Android application, I call the method to check if the application is running on the tablet using:

public boolean isTablet(Context context){ boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4); boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)== Configuration.SCREENLAYOUT_SIZE_MASK); return(xlarge || large); } 

if the method returns true (that is, the device satisfies one of these conditions)

I installed the topic in the conversation topic via:

 setTheme(R.style.MyTheme); 

where MyTheme is a theme that inherits from the parent Theme.Holo.Light.Dialog

This logic works great, but it gives me a weird effect in the background. The call wash is completely obscured, whereas if I just set the theme in the manifest, the background does not stand out a bit.

Update - code added

  private Context mClassContext = this; @Override public void onCreate(Bundle savedInstanceState){ if(isTablet(mClassContext)){ setTheme(R.style.MyTheme); } super.onCreate(savedInstanceState); setContentView(R.layout.myLayout); } 

How to do it?

+6
source share
1 answer

I seem to have found the answer to my question.

To avoid a black background:

In the android manifest, set all of your actions, which can be dialogs (if it's a tablet) for the dialog theme:

then in onCreate add this else case to change it for non-tablet devices (like phones)

 if(isTablet(mContext)){ setTheme(R.style.myDialogTheme);} else{ setTheme(R.style.MyTheme); } 
+10
source

All Articles