我刚创建了一个dialogfragment。这个片段的xml代码如下所示......
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/button_layout_background"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="8dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="@+id/timeLayout"
android:imeOptions="actionNext"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:text="Time"
android:textColor="#FFFFFF"
android:clickable="false"
android:focusableInTouchMode="false"
android:focusable="false"
android:paddingTop="5dp"
android:paddingBottom="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:text="Not Set"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:id="@+id/time_textView"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/button_layout_background"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="8dp"
android:layout_marginTop="8dp"
android:layout_alignParentLeft="true"
android:id="@+id/titleLayout"
android:layout_below="@id/timeLayout"
android:imeOptions="actionNext"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:text="Title"
android:textColor="#FFFFFF"
android:clickable="false"
android:focusableInTouchMode="false"
android:focusable="false"
android:paddingTop="5dp"
android:paddingBottom="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:text="Not Set"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:id="@+id/title_textView"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/button_layout_background"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="8dp"
android:layout_marginTop="8dp"
android:layout_alignParentLeft="true"
android:id="@+id/foodmanuLayout"
android:layout_below="@id/titleLayout"
android:imeOptions="actionNext"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:text="Food Menu"
android:textColor="#FFFFFF"
android:clickable="false"
android:focusableInTouchMode="false"
android:focusable="false"
android:paddingTop="5dp"
android:paddingBottom="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:text="Not Set"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:id="@+id/foodmenu_textView"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
/>
</LinearLayout>
现在,当我运行我的appliation。我可以通过点击布局来编写。但问题是在某个时候键盘没有隐藏(在完成所有布局的键入之前)。而且由于这个键盘,我看不到下一个布局内容。因此,如果我单击后退按钮,则对话框片段将被解除。我试图添加ScrollView,但它也不起作用。所以需要建议。有人可以告诉我
这是我的Dynamic EditText代码...我尝试使用InputMethodManager但无法实现...
private void showTitle(){
final EditText titleBox = new EditText(getActivity());
titleBox.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
titleBox.setHint("Add Title");
if(!titleView.getText().toString().equalsIgnoreCase("Not Set")){
titleBox.setText(titleView.getText());
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(titleBox);
/* InputMethodManager methodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
methodManager.hideSoftInputFromWindow(titleBox.getWindowToken(),0);*/
builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String text = titleBox.getText().toString();
if(text == null || text.isEmpty()){
titleView.setText("Not Set");
}else{
titleView.setText(text);
}
}
});
builder.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
builder.create().show();
}