怎么介绍自己做的网站效果图,网站网站开发设计,wordpress小程序插件,网站服务器停止响应是什么意思android-如何从单个editText移除焦点在我的应用程序中#xff0c;我只有一个button.seFocusableInTouchMode()#xff0c;以及一些button.requestFocus()#xff0c;按钮和一个微调器。 我认为#xff0c;我的EditText获得关注#xff0c;因为它是此活动中唯一可关注的视图…android-如何从单个editText移除焦点在我的应用程序中我只有一个button.seFocusableInTouchMode()以及一些button.requestFocus()按钮和一个微调器。 我认为我的EditText获得关注因为它是此活动中唯一可关注的视图。 我的EditText在字段上显示带有橙色边框和光标。现在我想从此字段中删除焦点(我不希望显示光标和边框)。 有没有办法做到这一点通过执行button.seFocusableInTouchMode()和button.requestFocus()我能够专注于按钮。但这突出了按钮显然不是我想要的。tobbenb3 asked 2020-01-01T03:23:17Z16个解决方案44 votes您是否尝试过使用旧商品View.clearFocus()MishaZ answered 2020-01-01T03:23:46Z38 votesandroid的新手。getWindow().getDecorView().clearFocus();这个对我有用..只需添加..您的布局应具有android:focusabletrueandroid:focusableInTouchModetrueZaraki answered 2020-01-01T03:24:15Z22 votes检查此问题和选定的答案阻止EditText专注于Activity启动。这很丑陋但是有效据我所知没有更好的解决方案。Maragues answered 2020-01-01T03:23:26Z15 votes我将尝试通过更多详细信息和理解来说明如何从EditText视图中删除焦点(闪烁的光标)。 通常这行代码应该可以工作editText.clearFocus()但可能是editText仍具有焦点的情况这是因为clearFocus()方法试图将焦点设置回活动/片段布局中的第一个可聚焦视图。因此如果您在活动中只有一个可聚焦的视图并且通常是您的EditText视图则clearFocus()将焦点再次设置为该视图并且对您来说clearFocus()无法正常工作。请记住默认情况下EditText视图是focusable(true)因此如果布局中只有一个EditText视图它将无法在屏幕上获得焦点。 在这种情况下您的解决方案将是在布局文件中找到父视图(某些布局例如LinearLayoutFramelayout)然后将此xml代码设置为该父视图android:focusabletrueandroid:focusableInTouchModetrue之后当您执行editText.clearFocus()时布局内的父视图将接受焦点并且您的editText将清除焦点。我希望这将有助于某人了解clearFocus()的工作方式。Sniper answered 2020-01-01T03:24:54Z3 votes我知道为时已晚但对于有同样需求的人您正在寻找editText.setFocusable(false)。lm2a answered 2020-01-01T03:25:15Z2 votes使用附带的代码将焦点移到“其他人”上如果您只想关闭键盘并释放焦点而不必在意谁会得到则可以这样做。像这样使用FocusHelper.releaseFocus(viewToReleaseFocusFrom)public class FocusHelper {public static void releaseFocus(View view) {ViewParent parent view.getParent();ViewGroup group null;View child null;while (parent ! null) {if (parent instanceof ViewGroup) {group (ViewGroup) parent;for (int i 0; i group.getChildCount(); i) {child group.getChildAt(i);if(child ! view child.isFocusable())child.requestFocus();}}parent parent.getParent();}}}文件该方法从子视图到视图树遍历并寻找第一个要聚焦的子对象。编辑您还可以为此使用APIView focusableView v.focusSearch(View.FOCUS_DOWN);if(focusableView ! null) focusableView.requestFocus();Sveinung Kval Bakken answered 2020-01-01T03:25:48Z2 votes我在editText上也遇到了类似的问题自从活动开始以来它就获得了关注。 我很容易解决此问题如下所示您将这段代码添加到包含xml中editText的布局中android:idid/linearlayoutandroid:focusableInTouchModetrue不要忘记android:id没有它我有一个错误。我对editText的另一个问题是一旦它获得了第一个焦点焦点就永远不会消失。 这是我的Java代码的一部分它有一个editText和一个捕获editText中的文本的按钮editText(EditText) findViewById(R.id.et1);tvhome (TextView)findViewById(R.id.tv_home);etBtn (Button) findViewById(R.id.btn_homeadd);etBtn.setOnClickListener(new View.OnClickListener(){Overridepublic void onClick(View v){tvhome.setText( editText.getText().toString() );//** this code is for hiding the keyboard after pressing the buttonView view Settings.this.getCurrentFocus();if (view ! null){InputMethodManager imm (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(view.getWindowToken(), 0);}//**editText.getText().clear();//clears the texteditText.setFocusable(false);//disables the focus of the editTextLog.i(onCreate().Button.onClickListener(), et.isfocused editText.isFocused());}});editText.setOnClickListener(new View.OnClickListener(){Overridepublic void onClick(View v){if(v.getId() R.id.et1){v.setFocusableInTouchMode(true);// when the editText is clicked it will gain focus again//** this code is for enabling the keyboard at the first click on the editTextif(v.isFocused())//the code is optional, because at the second click the keyboard shows by itself{InputMethodManager imm (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);}//**Log.i(onCreate().EditText.onClickListener(), et.isfocused v.isFocused());}elseLog.i(onCreate().EditText.onClickListener(), the listener didnt consume the event);}});希望对您有些帮助Lena answered 2020-01-01T03:26:26Z2 votes只是找到另一个视图并给予焦点即可。var refresher FindViewById(Resource.Id.refresher);refresher.RequestFocus();PmanAce answered 2020-01-01T03:26:46Z2 votes如果Edittext父级布局是Linear则添加android:focusabletrueandroid:focusableInTouchModetrue像下面android:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationverticalandroid:focusabletrueandroid:focusableInTouchModetrue............当Edittext父级布局为相对时则android:descendantFocusabilitybeforeDescendantsandroid:focusableInTouchModetrue喜欢android:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:descendantFocusabilitybeforeDescendantsandroid:focusableInTouchModetrue............OmiK answered 2020-01-01T03:27:19Z1 votes我已经做了很多尝试来清除编辑文本的焦点。 clearfocus()和focusable等东西对我没有用。因此我想到了让假的edittext获得关注的想法...android:layout_widthmatch_parentandroid:layout_heightmatch_parent...android:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:idid/fakeandroid:textSize1sp/然后在您的Java代码中View view Activity.this.getCurrentFocus();if (view ! null) {InputMethodManager imm (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(view.getWindowToken(), 0);fake.requestFocus();}它会隐藏键盘并移走具有该键盘的所有edittext的焦点。 而且正如您所看到的假的edittext在屏幕外无法看到navid answered 2020-01-01T03:27:49Z0 votes只要包括这行android:selectAllOnFocusfalse在与EditText布局相对应的XML段中。harshvardhan answered 2020-01-01T03:28:14Z0 votes您只需要从视图中清除焦点即可EditText.clearFocus()Mayank Bhatnagar answered 2020-01-01T03:28:34Z0 votes如果我正确理解了您的问题这应该可以帮助您TextView tv1 (TextView) findViewById(R.id.tv1);tv1 .setFocusable(false);kPieczonka answered 2020-01-01T03:28:54Z0 votes由于我是在小部件中而不是在活动中所以我做了getRootView()。clearFocus();kingston answered 2020-01-01T03:29:18Z0 votesandroid:clickablefalseandroid:focusablefalseandroid:textSize40dpandroid:textAlignmentcenterandroid:textStyleboldandroid:textAppearancestyle/Base.Theme.AppCompat.Light.DarkActionBarandroid:textAVIATORS/vithika answered 2020-01-01T03:29:34Z0 votes您只需要使用属性设置ViewGroupandroid:focusableInTouchModetrueViewGroup是包含每个子视图的布局。GaijinForce answered 2020-01-01T03:30:03Z