English 中文(简体)
安乐团:EditText,去除重点? [复制]
原标题:Android: Force EditText to remove focus? [duplicate]

我愿从埃德蒂特蒂特提尔中删除重点。 例如,如果钥匙板出现,而且用户把它藏在后面的纽顿,我希望重点和曲线消失。 如何做到这一点?

最佳回答

您可在<代码>onCreate上添加这一内容,并每次将Actective上填写钥匙。

你们还可以将重点从方案上转移到另一个项目。

 this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
问题回答

你们能够使治疗器和焦点消失

edittext.clearFocus();

但是,当关键委员会藏匿时,发现是一件艰巨的工作。

http://www.un.org/Depts/DGACM/index_chinese.htm

<LinearLayout 
    android:focusable="true"
    android:focusableInTouchMode="true" 
    android:clickable="true"
    android:layout_width="0px"
    android:layout_height="0px" />

或者,你也可以做同样的事,在埃迪特提之前添加这些内容。

<Button
    android:id="@+id/btnSearch"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:gravity="center"
    android:text="Quick Search"
    android:textColor="#fff"
    android:textSize="13sp"
    android:textStyle="bold" />

<EditText
    android:id="@+id/edtSearch"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="5dp"
    android:gravity="left"
    android:hint="Name"
    android:maxLines="1"
    android:singleLine="true"
    android:textColorHint="@color/blue"
    android:textSize="13sp"
    android:textStyle="bold" />

Remove focus but remain focusable:

editText.setFocusableInTouchMode(false);
editText.setFocusable(false);
editText.setFocusableInTouchMode(true);
editText.setFocusable(true);

EditText will lose focus, but can gain it again on a new touch event.

将这两种财产添加到贵方的布局中(摘自: Linear Layout, Relative Layout)。

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

它将做以下工作:

remove autofocus edittext android

它为我工作

<><>Edit>/strong> 在他们建议使用线性语言的链接中,简单的观点将发挥作用。

<View
    android:id="@+id/focus_thief"
    android:layout_width="1dp"
    android:layout_height="1dp"
    android:focusable="true"
    android:focusableInTouchMode="true" />

然后,如果将“这一”放在布局(作为首要重点项目)的顶端,则要求<代码>clearFocus(>的工作。

你还可以包括android:windowSoftInputMode=“stateAlwaysHidden”,载于你的行动部分。

这相当于:

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

but in XML way.

FYI, 您也可以用密码隐藏钥匙板:

// hide virtual keyboard
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mYourEditText.getWindowToken(), 0);

在活动开始时隐藏着键盘,在Create(Create)写下以下代码。

InputMethodManager imm = (InputMethodManager)
getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);

• 明确重点,从编辑中删除 cur。

editText.clearFocus();

editText.setCursorVisible(false);

try to use this one on your view it worked for me:

<View
    android:id="@+id/fucused"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:focusableInTouchMode="true"/>

添加到您的括号中:<>EditText。

页: 1

如果你不使用否决权,那么问题依然存在。

用户代码:LinearLayout

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

希望能帮助你们。

这是我对SO的第一次回答,因此,如果存在错误,对我来说不会太严厉。

在SO周围几乎没有答案,但我感到,有人敦促我拿出完整的解决办法,使我有钱。 如果我不向每个人提供各自的信贷,我就从整个旁边的那片东西gra。

(我简化了我的结果,导致我的看法太多,我不 with大麻 sp,并将尽量使之具有通用性......)

对于您的布局,您需要一名父母 EditText 即:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
              android:orientation="vertical"
              android:layout_width="match_parent" 
              android:layout_height="match_parent"
              android:id="@+id/lytContainer"
              android:descendantFocusability="beforeDescendants"
              android:focusableInTouchMode="true">
<EditText android:layout_width="fill_parent" 
              android:layout_height="wrap_content" 
              android:id="@+id/etEditor"
              android:inputType="number"
              android:layout_gravity="center" 
              android:hint="@string/enter_your_text"
              android:textColor="@android:color/darker_gray" 
              android:textSize="12dp"
              android:textAlignment="center" 
              android:gravity="center" 
              android:clickable="true"/>
</LinearLayout>

因此,我在这里需要几件事。 我需要拥有我的EditText——即:

甲型六氯环己烷

此外,

android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"

因此,在EditText上不再侧重于进入Actative<>>>和之后进入Actative。 在设定这一环境时,你可以设定on TouchListener,将其重点从 EditText

Now, in the Activity:

package com.at.keyboardhide;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnTouchListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;

public class MainActivity extends Activity implements OnTouchListener{
private EditText getEditText;
private LinearLayout getLinearLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    setContentView(R.layout.keyboardmain);
    getEditText = (EditText)findViewById(R.id.etEditor);
    getLinearLayout = (LinearLayout)findViewById(R.id.lytContainer);
    getLinearLayout.setOnTouchListener(this);

    getEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                Log.d("EDTA", "text was entered.");
                getEditText.clearFocus();
                imm.hideSoftInputFromWindow(barcodeNo.getWindowToken(), 0);
                return true;
            }
            return false;
        }
    });
}
@Override
public boolean onTouch(View v, MotionEvent event) {
    if(v==getLinearLayout){
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(getEditText.getWindowToken(), 0);
        getEditText.clearFocus();
        return true;
        }
    return false;
    }
}

我在此问页上找到的对借方的答复很少,而我在上找到的活动解决办法。 我不得不指出的其余部分是关于EditText的焦点,我在OnEditorActionListener的TouchLister上加了这一重点。

Hope this helps someone and saves their time. :)

Cheers, Z.

在你们的评论中,你询问是否可以把另一个观点集中起来,而不是把EditText集中起来。 是的。 使用<代码>.requestFocus()方法,供您在开始时(按Create()方法)重点讨论。

其他观点还将削减一些法典。 (例如藏匿钥匙板的代码)

I had the same problem. It made me more than crazy.

我收到了一份长篇的诊断书,该书附有一条长线Layout的表片,其中包含一个“寻求巴尔”和一个EditText。

第一个EditText在显示Dialog和完成对EditText主板的编辑之后,始终有自动焦点,关键板仍然可见。

I tried nearly all solutions of this thread and none worked for me.

因此,我在这里的<>简单解决办法:(text = EditText)

text.setOnEditorActionListener( new OnEditorActionListener( ){
    public boolean onEditorAction( TextView v, int actionId, KeyEvent event ){
        if( (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) ||
            (actionId == EditorInfo.IME_ACTION_DONE) ){
            text.clearFocus( );
            InputMethodManager iMgr = null;
            iMgr = (InputMethodManager)mContext.getSystemService( Context.INPUT_METHOD_SERVICE );
            iMgr.hideSoftInputFromWindow( text.getWindowToken(), 0 );
        }
        return true;
    }
});

顺便提一下:

//setFocusableInTouchMode( true )
//setFocusable( true )
//setDescendantFocusability( ViewGroup.FOCUS_BEFORE_DESCENDANTS )

目 录 I didn t 使用了一种空间项目,如1dp的宽度和高度。

Hopefully it helps someone :D

editText.setFocusableInTouchMode(true)

The EditText will be able to get the focus when the user touch it. When the main layout (activity, dialog, etc.) becomes visible the EditText doesn t automatically get the focus even though it is the first view in the layout.

您也可在明确的行动部分包括android:windowSoftInputMode=“stateAlwaysHidden”

这相当于:

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

您可以避免对贵要素的任何关注,具体做法是确定母元素的属性android:辈子/长子”。

例如:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/search__scroller"
android:descendantFocusability="blocksDescendants"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ScrollView>

这里,归属感和roid体:将后代作为“锁定者”的主食,阻碍了对儿童内容的重视。

https://developer.android.com/fer/android/view/Viewgroup.html#setDescendant Foability%28int%29”rel=“nofollow”>。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...