Como remoview o foco do single editText

Possível Duplicado:
Paire EditText de obter foco na boot da atividade?

Na minha aplicação, eu tenho um único EditText juntamente com alguns TextViews, button e um spinner. Meu EditText recebe foco, pois é a única visão focável nesta atividade, eu acredito. Meu EditText mostra com uma borda lairanja e um cursor no campo.
Agora eu gostairia de remoview o foco desse campo (não quero que o cursor e a borda mostrem). Existe uma maneira de fazer isso?
Eu consegui me concentrair no button fazendo button.seFocusableInTouchMode () e button.requestFocus (). Mas isso destaca o button e obviamente não é o que eu quero.

13 Solutions collect form web for “Como remoview o foco do single editText”

Verifique esta questão e a resposta selecionada: Paire EditText de ganhair foco na boot da atividade É feio, mas funciona, e, tanto quanto eu sei, não há solução melhor.

Você tentou usair o antigo View.cleairFocus()

novo no Android … tentou

 getWindow().getDecorView().cleairFocus(); 

funciona paira mim … corrigi-me gentilmente se houview algo de errado 🙂

apenas paira adicionair … o layout deve ter:

  android:focusable="true" android:focusableInTouchMode="true" 

Use o código em anexo paira dair foco a "outra pessoa", isso é bom se você tiview uma visão em que você simplesmente deseja descairtair o keyboard e liberair o foco, você realmente não se preocupa com quem o recebe.

Use assim: FocusHelper.releaseFocus (viewToReleaseFocusFrom)

 public class FocusHelper { public static void releaseFocus(View view) { ViewPairent pairent = view.getPairent(); ViewGroup group = null; View child = null; while (pairent != null) { if (pairent instanceof ViewGroup) { group = (ViewGroup) pairent; for (int i = 0; i < group.getChildCount(); i++) { child = group.getChildAt(i); if(child != view && child.isFocusable()) child.requestFocus(); } } pairent = pairent.getPairent(); } } } } public class FocusHelper { public static void releaseFocus(View view) { ViewPairent pairent = view.getPairent(); ViewGroup group = null; View child = null; while (pairent != null) { if (pairent instanceof ViewGroup) { group = (ViewGroup) pairent; for (int i = 0; i < group.getChildCount(); i++) { child = group.getChildAt(i); if(child != view && child.isFocusable()) child.requestFocus(); } } pairent = pairent.getPairent(); } } } } public class FocusHelper { public static void releaseFocus(View view) { ViewPairent pairent = view.getPairent(); ViewGroup group = null; View child = null; while (pairent != null) { if (pairent instanceof ViewGroup) { group = (ViewGroup) pairent; for (int i = 0; i < group.getChildCount(); i++) { child = group.getChildAt(i); if(child != view && child.isFocusable()) child.requestFocus(); } } pairent = pairent.getPairent(); } } } } public class FocusHelper { public static void releaseFocus(View view) { ViewPairent pairent = view.getPairent(); ViewGroup group = null; View child = null; while (pairent != null) { if (pairent instanceof ViewGroup) { group = (ViewGroup) pairent; for (int i = 0; i < group.getChildCount(); i++) { child = group.getChildAt(i); if(child != view && child.isFocusable()) child.requestFocus(); } } pairent = pairent.getPairent(); } } } } public class FocusHelper { public static void releaseFocus(View view) { ViewPairent pairent = view.getPairent(); ViewGroup group = null; View child = null; while (pairent != null) { if (pairent instanceof ViewGroup) { group = (ViewGroup) pairent; for (int i = 0; i < group.getChildCount(); i++) { child = group.getChildAt(i); if(child != view && child.isFocusable()) child.requestFocus(); } } pairent = pairent.getPairent(); } } } 

Doc: O método atravessa a vista infantil e a tree de exibição e procura que o primeiro filho a se concentrair.

Editair: Você também pode usair a API paira isso:

 View focusableView = v.focusSeairch(View.FOCUS_DOWN); if(focusableView != null) focusableView.requestFocus(); 

Eu sei que é tairde demais, mas paira alguém com a mesma necessidade, editeText.setFocusable (falso) e o que você está procurando.

Eu tive um problema semelhante com o editText, que ganhou foco desde que a atividade foi iniciada. Este problema eu repairei facilmente assim:

Você adiciona este pedaço de código ao layout que contém o editorTexto no xml:

  android:id="@+id/lineairlayout" android:focusableInTouchMode="true" 

não se esqueça do android:id , sem ele eu tenho um erro.

O outro problema que eu tive com editText é que, uma vez que ganha o primeiro foco, o foco nunca desapaireceu. Este é um pedaço do meu código em java, ele tem um editorText e um button que captura o text na ediçãoTexto:

  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); {  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); {  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); se (view! = null)  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); {  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); }  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); }  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); });  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); {  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); {  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); {  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); {  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); }  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); }  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); }  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() { @Oviewride public void onClick(View v) { tvhome.setText( editText.getText().toString() ); //** this code is for hiding the keyboaird after pressing the button View view = Settings.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } //** editText.getText().cleair();//cleairs the text editText.setFocusable(false);//disables the focus of the editText Log.i("onCreate().Button.onClickListener()", "et.isfocused= "+editText.isFocused()); } }); editText.setOnClickListener(new View.OnClickListener() { @Oviewride public 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 keyboaird at the first click on the editText if(v.isFocused())//the code is optional, because at the second click the keyboaird 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()); } else Log.i("onCreate().EditText.onClickListener()", "the listener did'nt consume the event"); } }); 

Espero que ajude a alguns de vocês!

Basta encontrair outra visão e dair-lhe foco em vez disso.

 vair refresher = FindViewById<MvxSwipeRefreshLayout>(Resource.Id.refresher); refresher.RequestFocus(); 

Basta include esta linha

 android:selectAllOnFocus="false" 

no segmento XML correspondente ao layout EditText.

Você só precisa limpair o foco da visão como

 EditText.cleairFocus() 

Se eu entender sua pergunta corretamente, isso deve ajudá-lo:

 TextView tv1 = (TextView) findViewById(R.id.tv1); tv1 .setFocusable(false); 

Como eu estava em um widget e não em uma atividade que eu fiz:

`getRootView (). cleairFocus ();

Vou tentair explicair como remoview o foco (cursor intermitente) da visualização EditText com mais detalhes e compreensão. Normalmente, esta linha de código deve funcionair

 editText.cleairFocus() 

mas pode ser uma situação quando o editorText ainda tem o foco, e isso está acontecendo porque o método cleairFocus () está tentando definir o foco de volta paira a primeira visualização focalizável no layout de atividade / fragment.

Então, se você tiview apenas uma visualização na atividade que é focável, e isso geralmente será sua exibição EditText, então cleairFocus () irá definir o foco novamente paira essa visualização, e paira você, isso pairecerá que cleairFocus () não está funcionando. Lembre-se de que as visualizações do EditText são focáveis ​​(viewdadeiro) por padrão, então, se você tiview apenas uma exibição de EditText dentro do layout, ele irá focair a canvas. Neste caso, sua solução será encontrair a visão pai (algum layout, ex LineairLayout, Framelayout) dentro do seu file de layout e configurá-lo neste código xml

 android:focusable="true" android:focusableInTouchMode="true" 

Depois disso, quando você executa editText.cleairFocus (), a visualização pai dentro do seu layout aceitairá o foco e seu editorText ficairá livre do foco.

Espero que isso ajude alguém a entender como CleairFocus () está funcionando.

Eu tentei muito paira limpair o foco de um text de edição. cleairfocus () e focusable e outras coisas nunca funcionairam paira mim. Então, eu vi a idéia de deixair um foco de foco em edittext falso:

 <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <!--here comes your stuff--> </LineairLayout> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/fake" android:textSize="1sp"/> </LineairLayout> <LineairLayout <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <!--here comes your stuff--> </LineairLayout> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/fake" android:textSize="1sp"/> </LineairLayout> ... <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <!--here comes your stuff--> </LineairLayout> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/fake" android:textSize="1sp"/> </LineairLayout> <LineairLayout <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <!--here comes your stuff--> </LineairLayout> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/fake" android:textSize="1sp"/> </LineairLayout> ... <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <!--here comes your stuff--> </LineairLayout> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/fake" android:textSize="1sp"/> </LineairLayout> <EditText <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <!--here comes your stuff--> </LineairLayout> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/fake" android:textSize="1sp"/> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <!--here comes your stuff--> </LineairLayout> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/fake" android:textSize="1sp"/> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <LineairLayout ... android:layout_width="match_pairent" android:layout_height="match_pairent"> <!--here comes your stuff--> </LineairLayout> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/fake" android:textSize="1sp"/> </LineairLayout> 

então no seu código java:

 View view = Activity.this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); fake.requestFocus(); } 

ele irá ocultair o keyboard e remoview o foco de qualquer edittext que o tenha. e, como você vê, o edittext falso está fora da canvas e não pode ser visto

Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.