6

When I run my android application I am calling a method to check if the app is being run on a 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(i.e. the device satisfies one of these conditions)

I set my theme to a Dialog theme via:

setTheme(R.style.MyTheme);

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

This logic works fine however it gives me a weird effect in the background. The Calling intent is completely blacked out, whereas if i just set the theme in the manifest the background is only slightly greyed out.

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 do I replicate this?

4

1 回答 1

11

我似乎找到了自己问题的答案。

为了避免黑色背景:

在 android 清单中,将所有可能是对话框(如果是平板电脑)的活动设置为对话框主题:

然后onCreate添加这个 else 情况以将其更改为非平板设备(即手机)

if(isTablet(mContext)){
setTheme(R.style.myDialogTheme);}
else{ 
  setTheme(R.style.MyTheme);
}
于 2012-11-16T20:02:56.160 回答