【发布时间】:2016-06-08 07:58:05
【问题描述】:
我正在尝试制作一个弹出窗口,您可以在其中读取和写入一些 cmets(例如在 facebook 应用程序上)。它工作得很好,但是当我选择编辑文本时,软键盘会隐藏编辑文本,所以我看不到我在写什么。我尝试了在大多数类似主题中找到的解决方案,我在清单中的活动中添加了这一行:
android:windowSoftInputMode="stateVisible|adjustResize"/>
但它不起作用。
这是我的一些代码:
private PopupWindow popWindow;
public void onShowPopup(View v){
LayoutInflater layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// inflate the custom popup layout
final View inflatedView = layoutInflater.inflate(R.layout.comments_popup_layout,null);
// find the ListView in the popup layout
ListView listView = (ListView)inflatedView.findViewById(R.id.commentsListView);
// get device size
Display display = getWindowManager().getDefaultDisplay();
final Point size = new Point();
display.getSize(size);
// fill the data to the list items
setSimpleList(listView);
// set height depends on the device size
popWindow = new PopupWindow(inflatedView, size.x - 200,size.y - 500, true );
popWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.comments_bg));
// make it focusable to show the keyboard to enter in `EditText`
popWindow.setFocusable(true);
// make it outside touchable to dismiss the popup window
popWindow.setOutsideTouchable(true);
// show the popup at bottom of the screen and set some margin at bottom ie,
popWindow.showAtLocation(v, Gravity.BOTTOM, 0,100);
}
void setSimpleList(ListView listView){
ArrayList<String> contactsList = new ArrayList<String>();
for (int index = 0; index < 10; index++) {
contactsList.add("I am @ index " + index + " today " + Calendar.getInstance().getTime().toString());
}
listView.setAdapter(new ArrayAdapter<String>(ListEddystoneActivity.this,
R.layout.comments_list_item, android.R.id.text1,contactsList));
}
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:id="@+id/headerLayout"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:gravity="center">
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some One and 20 Others Like this"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_margin="5dp"/>
</LinearLayout>
<ListView
android:id="@+id/commentsListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_below="@id/headerLayout"
android:paddingBottom="50dp"
android:layout_marginBottom="0dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="@+id/writeCommentView">
<EditText
android:id="@+id/writeComment"
android:hint="Write a Comment"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="12dp"
android:textColor="@color/black"
android:background="#00000000"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
谢谢你:)
【问题讨论】:
-
听起来你的意思是实现一个自动完成的editText?
-
感谢visionix,我不明白你所说的“自动完成editText”是什么意思,但我想做的是一个带有列表视图和editText的弹出窗口。
-
tutorialspoint.com/android/android_auto_complete.htm 滚动到底部,看看这是否是您正在寻找的功能
-
是的,但在本例中,编辑文本显示在主活动的布局中,在我的情况下,它位于 PopupWindow 中:/ 我认为这就是为什么 adjustResize 对我不起作用。
-
它不显示在布局中,它是在activity布局之上的一个弹窗
标签: android android-edittext android-softkeyboard layout-inflater android-popupwindow