0
我在编程时遇到了问题。我认为我已经通过为对话框的主体指定了一个固定的百分比高度来解决它。我认为这是不好的形式,因为用户可能有一个纤细的显示屏,或设置大的字体,这将削减EditText框。Android对话框布局破解如何修复?
无论如何,该解决方案已超越模拟器失败。
它看起来像Android是分配一个固定的高度来一个对话框,如果我的自定义标题吞噬了太多这样的高度,挤一切了。这是正确的,我该如何解决它? 问题
public class GetUserNameDialogFragment extends DialogFragment {
final String TAG = "GetUserNameDialog";
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.MyAlertDialogStyle);
//TODO getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
LayoutInflater inflater = getActivity().getLayoutInflater();
final View sunburst =inflater.inflate(R.layout.dialog_user_name, null);
builder.setView(sunburst);
builder.setCancelable(false)
.setPositiveButton("Let's go!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Log.wtf(TAG, "button press");
EditText name = (EditText) sunburst.findViewById(R.id.nameEditText);
String userName = name.getText().toString().trim();
//TODO needs to be validated
SharedPreferences sharedPref = getActivity().getSharedPreferences("userDetails", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("userName", userName);
editor.commit();
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
这里的XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@drawable/ic_ball_sunburst_classic"
android:background="@color/colorAccent"
/>
<LinearLayout
android:layout_width="250dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_height="125dp">
<EditText
android:id="@+id/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:hint="Enter your first name"/>
</LinearLayout>
</LinearLayout>
所有帮助非常感谢,我的应用程序的第一印象 - 什么是灾难!