我正在尝试显示几乎全屏的DialogFragment.但我不知道怎么做不到.
我展示Fragment的方式直接来自android开发者文档
FragmentManager f = ((Activity)getContext()).getFragmentManager();
FragmentTransaction ft = f.beginTransaction();
Fragment prev = f.findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
// Create and show the dialog.
DialogFragment newFragment = new DetailsDialogFragment();
newFragment.show(ft, "dialog");
Run Code Online (Sandbox Code Playgroud)
我知道天真地尝试将片段中的RelativeLayout设置为fill_parent和一些minWidth和minHeight.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="1000px"
android:minHeight="600px"
android:background="#ff0000">
Run Code Online (Sandbox Code Playgroud)
我知道期望DialogFragment填满屏幕的大部分.但我似乎只是垂直调整大小,但只是水平固定宽度.
我还尝试在代码中设置窗口属性,如下所示:http://groups.google.com/group/android-developers/browse_thread/thread/f0bb813f643604ec.但这也没有帮助.
我可能误解了Android处理Dialogs的方式,因为我对它不熟悉.我怎么能这样做?有没有其他方法可以实现我的目标?
Android设备:
华硕EeePad Transformer
Android 3.0.1
更新: 我现在设法将其全屏显示,片段中包含以下代码
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, android.R.style.Theme_Holo_Light);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不是我想要的.我肯定需要在对话框周围显示一个小"填充"来显示背景.
任何想法如何实现?
我正在为我的应用程序构建一个自定义警报对话框我已编写代码及其工作但唯一的问题是它的大小不会根据我在对话框中的内容进行调整.下面是我的代码:
public class CustomDialogBoxActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(R.id.Button01main);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Dialog myDialog = new Dialog(CustomDialogBoxActivity.this);
myDialog.setContentView(R.layout.dialog_sms_layout);
myDialog.setTitle("Select any one");
Button ok = (Button)myDialog.findViewById(R.id.buttonOK);
final RadioGroup radioGrp = (RadioGroup)myDialog.findViewById(R.id.radioGroupSmsDialog);
final CheckBox mob1 = (CheckBox)myDialog.findViewById(R.id.checkBoxMob1);
final CheckBox mob2 = (CheckBox)myDialog.findViewById(R.id.checkBoxMob2);
mob1.setText("9029691986");
mob2.setText("99263911766");
ok.setOnClickListener(this);
ok.setOnClickListener(new OnClickListener() {
@Override
public void …Run Code Online (Sandbox Code Playgroud)