单击特定按钮后,屏幕上会出现一个弹出窗口。弹出窗口中有一个 edittext 对象,但我不能写它,因为键盘没有出现。其次,弹出窗口的父视图上的其他按钮仍然是可点击的。我该如何解决这些问题?我的代码:
edit_text_popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dip"
android:background="@color/conn_text" >
<EditText
android:id="@+id/editTextInPopup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hello_world"
android:padding="5dip"
android:background="@color/blue3">
</EditText>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:padding="10dip">
<Button
android:id="@+id/popupcommitbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ok"/>
<Button
android:id="@+id/popupcancelbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel"
android:layout_alignParentRight="true" />
</RelativeLayout>
</LinearLayout>
弹出窗口被称为:
public class GroupConnections extends Activity implements OnClickListener {
Category thiscat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_group_connections);
View addMoreConnButton =findViewById(R.id.attachMorePeopleButton);
View editPropButton = findViewById(R.id.editCategoryPropertiesButton);
addMoreConnButton.setOnClickListener(this);
editPropButton.setOnClickListener(this);
//get selected category
int catId = getIntent().getExtras().getInt("categoryid");
thiscat = (Category)SocialRssModel.Instance().holders.get(catId);
//set text views
TableRow tabler = (TableRow)findViewById(R.id.tableRow1);
TextView cateNameTextView = (TextView)tabler.findViewById(R.id.numOfContentsTextView2);
cateNameTextView.setText(thiscat.getName());
tabler = (TableRow)findViewById(R.id.tableRow2);
CheckBox enable = (CheckBox)tabler.findViewById(R.id.notificationCheckBox);
enable.setChecked(thiscat.isSelected());
}
/**
* Button listeners are specified
*/
public void onClick(View v) {
switch (v.getId()) {
case R.id.attachMorePeopleButton:
Intent i = new Intent(this, AddMoreConnections.class);
startActivity(i);
break;
case R.id.editCategoryPropertiesButton:
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.edit_text_popup, null);
final PopupWindow editpopup = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
//specify cancel button
View cancelbutton = popupView.findViewById(R.id.popupcancelbutton);
cancelbutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
editpopup.dismiss();
}
});
//specify edittext
editpopup.setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
editpopup.showAsDropDown(findViewById(R.id.editCategoryPropertiesButton), 0, -30);
break;
// More buttons go here (if any) ...
}
}
}
AndroidManifest 中显示 softInputMode 的 Activity 标记未隐藏:
<activity
android:name=".GroupConnections"
android:label="@string/app_name" >
</activity>