我最近在发布之前开始测试,所以我可以看到我的应用在其他设备上的样子。出于某种原因,DialogFragment的背景似乎不适用于5之前的Android版本的手机,因此在所有测试中只有Android 5.0+显示背景,而4.4及以下只是默认的黑暗对话。
背景在布局.xml文件中定义如下:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:id="@+id/relativeLayout"
android:gravity="center_horizontal"
android:background="@drawable/phone_like_bc"
android:orientation="horizontal">
但它没有显示4.4以下版本的背景......为什么会发生这种情况?
我的DialogFragment类:
public class SettingDialog extends DialogFragment implements View.OnClickListener {
Context c;
ComputerClass cl;
Game game;
public static SettingDialog newInstance() {
SettingDialog f = new SettingDialog();
// Supply num input as an argument.
Bundle args = new Bundle();
f.setArguments(args);
return f;
}
public void params(Context c, ComputerClass cl, Game game){
this.c = c;
this.cl = cl;
this.game = game;
}
@Override
public void onCreate(Bundle sis){
super.onCreate(sis);
// setContentView(null);
int style, theme;
style = DialogFragment.STYLE_NO_FRAME;
theme = android.R.style.Theme_Holo_Dialog;
setStyle(style, theme);
}
private View v;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.settings, container, false);
this.v = v;
setButtons();
return v;
}
Button bSettBack, bChangeLanguage;
CheckBox cbSound;
private void setButtons(){
bSettBack = (Button) v.findViewById(R.id.bSettBack);
bChangeLanguage = (Button) v.findViewById(R.id.bChangeLanguage);
cbSound = (CheckBox) v.findViewById(R.id.cbSound);
bChangeLanguage.setOnClickListener(this);
bSettBack.setOnClickListener(this);
cbSound.setOnClickListener(this);
updateCBSound();
}
private boolean music;
private void updateCBSound(){
this.music = cl.music;
cbSound.setChecked(music);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bSettBack:
dismiss();
break;
case R.id.cbSound:
music = Maths.invertBoolean(music);
cl.music = music;
break;
case R.id.bChangeLanguage:
cl.save();
game.showLanguageScreen();
break;
}
}
}
我只使用默认文件夹。这意味着所有版本只有一个布局文件。
有什么想法吗?