kan*_*idj 6 android themes dialog
当我运行我的Android应用程序时,我正在调用一种方法来检查应用程序是否在平板电脑上运行:
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);
}
Run Code Online (Sandbox Code Playgroud)
如果方法返回true(即设备满足其中一个条件)
我通过以下方式将主题设置为Dialog主题:
setTheme(R.style.MyTheme);
Run Code Online (Sandbox Code Playgroud)
哪个MyTheme是从父级继承的主题Theme.Holo.Light.Dialog
这个逻辑工作正常,但它在后台给我一个奇怪的效果.调用意图完全被遮挡,而如果我只是在清单中设置主题,则背景仅略微变灰.
更新 - 添加了代码
private Context mClassContext = this;
@Override
public void onCreate(Bundle savedInstanceState){
if(isTablet(mClassContext)){
setTheme(R.style.MyTheme);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.myLayout);
}
Run Code Online (Sandbox Code Playgroud)
我该如何复制这个?
kan*_*idj 11
我似乎找到了自己问题的答案.
为了避免黑色背景:
在android清单中,将所有可能是对话框(如果是平板电脑)的活动设置为对话框主题:
然后onCreate添加其他情况来改变非平板设备(即手机)
if(isTablet(mContext)){
setTheme(R.style.myDialogTheme);}
else{
setTheme(R.style.MyTheme);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
992 次 |
| 最近记录: |