Android Can';t获取编辑文本以获取焦点和弹出键盘
我无法在末尾的Android Can';t获取编辑文本以获取焦点和弹出键盘,android,android-edittext,Android,Android Edittext,我无法在末尾的EditText框上设置焦点。我已经尝试了谷歌的几乎所有伎俩!我无法使它聚焦,也无法使用键盘 我也尝试过设置android:WindowsOfInputMode=“adjustResize”,但这也没有解决问题 请帮忙 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
EditText
框上设置焦点。我已经尝试了谷歌的几乎所有伎俩!我无法使它聚焦,也无法使用键盘
我也尝试过设置android:WindowsOfInputMode=“adjustResize”,但这也没有解决问题
请帮忙
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@android:color/white"
android:touchscreenBlocksFocus="false">
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spnIncidentCategory"
android:layout_alignParentTop="false"
android:focusable="true"
android:focusableInTouchMode="true"
android:spinnerMode="dropdown"
android:clickable="true"
android:background="@drawable/iv_border"
android:padding="10dp"
android:layout_alignParentRight="true"
android:layout_alignLeft="@+id/textView24"
android:layout_below="@+id/textView24" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@mipmap/drop_down"
android:layout_alignParentTop="false"
android:layout_alignTop="@+id/spnIncidentCategory"
android:id="@+id/imgSpinner1"
android:focusableInTouchMode="false"
android:background="@drawable/border"
android:layout_alignEnd="@id/spnIncidentCategory" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/pbSendInfo"
android:visibility="invisible"
android:indeterminate="true"
android:progressTint="#ffffffff"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:layout_alignParentTop="false"
android:layout_alignParentBottom="false" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/txtPlaceHolder"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#ff000000"
android:layout_below="@+id/spnIncidentCategory" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please Select an Incident Category"
android:id="@+id/textView24"
android:layout_alignParentTop="false"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:textColor="#000000"
android:layout_below="@+id/pbSendInfo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please Select an Incident Description"
android:id="@+id/textView25"
android:textColor="#000000"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/txtPlaceHolder" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spnIncidentDescription"
android:focusable="true"
android:focusableInTouchMode="true"
android:spinnerMode="dropdown"
android:clickable="true"
android:background="@drawable/iv_border"
android:padding="10dp"
android:layout_alignStart="@+id/spnIncidentCategory"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView25"
android:layout_alignLeft="@+id/textView25" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/txtPlaceHolder2"
android:textColor="#ff000000"
android:layout_below="@+id/spnIncidentDescription"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@mipmap/drop_down"
android:id="@+id/imgSpinner2"
android:focusableInTouchMode="false"
android:background="@drawable/border"
android:layout_alignTop="@+id/spnIncidentDescription"
android:layout_alignEnd="@id/spnIncidentDescription" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter any comment that will help resolve the issue faster"
android:id="@+id/textView26"
android:textColor="#000000"
android:layout_below="@+id/txtPlaceHolder2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/txtPlaceHolder3"
android:textColor="#ff000000"
android:layout_below="@+id/txtUserComments" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/btnSendInfo"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="false"
android:layout_below="@+id/txtPlaceHolder3"
android:src="@mipmap/send_info"
android:background="@drawable/border"
android:layout_marginTop="5dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="150dp"
android:id="@+id/txtUserComments"
android:editable="true"
android:textColor="#000000"
android:textIsSelectable="true"
android:clickable="true"
android:padding="5dp"
android:gravity="top"
android:hint="Enter Your Comments"
android:textColorHint="#86acafb9"
android:selectAllOnFocus="true"
android:nestedScrollingEnabled="true"
android:focusableInTouchMode="true"
android:focusable="true"
android:enabled="true"
android:elevation="@dimen/abc_action_bar_default_padding_material"
android:inputType="textImeMultiLine|text|textMultiLine"
android:layout_below="@+id/textView26"
android:elegantTextHeight="true"
android:layout_marginTop="10dp">
<requestFocus/>
</EditText>
</RelativeLayout>
enter code here
在这里输入代码
Android中的软键盘是高度不可预测的。有几个问题与编辑文本焦点和显示键盘有关。尝试以下方法以编程方式在应用程序中显示或隐藏键盘
public static void hideKeyboard(FragmentActivity activity) {
// Check if no view has focus:
View view = activity.getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
public static void showKeyboard(FragmentActivity activity) {
View view = activity.getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInputFromInputMethod(view.getWindowToken(), InputMethodManager.SHOW_IMPLICIT);
}
}
Android中的软键盘是高度不可预测的。有几个问题与编辑文本焦点和显示键盘有关。尝试以下方法以编程方式在应用程序中显示或隐藏键盘
public static void hideKeyboard(FragmentActivity activity) {
// Check if no view has focus:
View view = activity.getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
public static void showKeyboard(FragmentActivity activity) {
View view = activity.getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInputFromInputMethod(view.getWindowToken(), InputMethodManager.SHOW_IMPLICIT);
}
}
你有没有尝试过以编程的方式给予关注
text.requestFocus()代码>您是否尝试以编程方式提供焦点
text.requestFocus()代码>
EditText
中的这一行导致了问题。移除它,它应该会工作
EditText
中的这一行导致了问题。移除它,它应该会工作。@VipuKumar-我尝试过这个,并从OnFocusChange调用了它。但是这里没有调用它的是我的代码txtComments.setOnFocusChangeListener(新视图.OnFocusChangeListener(){#覆盖公共void onFocusChange(视图v,布尔hasFocus){Toast.makeText(rootView.getContext(),hasFocus+“”,Toast.LENGTH_LONG)。show();showKeyboard(getActivity()); } });您是否以编程方式调用了et.requestFocus()?@VipuKumar-我尝试了这个方法,并从OnFocusChange调用了它。但是这里没有调用它的是我的代码txtComments.setOnFocusChangeListener(新视图.OnFocusChangeListener(){#覆盖公共void onFocusChange(视图v,布尔hasFocus){Toast.makeText(rootView.getContext(),hasFocus+“”,Toast.LENGTH_LONG)。show();showKeyboard(getActivity()); } });您是否以编程方式调用了et.requestFocus()?是的,我一创建它就调用了。是的,我一创建它就调用了。Yazici-我不知道为什么会出现这个问题,但它确实存在。现在它可以正常工作了。谢谢!接受答案。亚齐奇-我不知道为什么会有这个问题,但事实确实如此。现在它可以正常工作了。谢谢!接受答案。