android.widget.EditText#clearFocus ( )源码实例Demo

下面列出了android.widget.EditText#clearFocus ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: HtmlNative   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    mSharedPreference = getSharedPreferences("htmlnative-demo", MODE_PRIVATE);
    String url = mSharedPreference.getString("url", "");

    mContainer = (RelativeLayout) findViewById(R.id.relative_view);
    mSearch = (EditText) findViewById(R.id.search_editbox);
    mSearch.setText(url);
    mGo = (ImageButton) findViewById(R.id.search_go_btn);
    mGo.setOnClickListener(this);
    mLoader = new RemoteViewLoader(this);
    mSearch.clearFocus();
}
 
@NonNull
private View.OnTouchListener getClearListener(final EditText editText) {
    return new View.OnTouchListener() {
        final int DRAWABLE_LEFT = 0;
        final int DRAWABLE_TOP = 1;
        final int DRAWABLE_RIGHT = 2;
        final int DRAWABLE_BOTTOM = 3;

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                int leftEdgeOfRightDrawable = editText.getRight()
                        - editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width();
                // when EditBox has padding, adjust leftEdge like
                // leftEdgeOfRightDrawable -= getResources().getDimension(R.dimen.edittext_padding_left_right);
                if (event.getRawX() >= leftEdgeOfRightDrawable) {
                    // clicked on clear icon
                    editText.setText("");
                    editText.clearFocus();
                    return true;
                }
            }
            return false;
        }
    };
}
 
源代码3 项目: android-project-wo2b   文件: CommentActivity.java
@Override
protected void initView()
{
	if (!TextUtils.isEmpty(mTitle))
	{
		setActionBarTitle(mTitle);
	}

	send_comment = (TextView) findViewById(R.id.send_comment);
	et_content = (EditText) findViewById(R.id.et_content);
	send_comment.setOnClickListener(this);
	et_content.setSelected(false);
	et_content.clearFocus();
	
	//ViewUtils.hideSoftInput(this);
	//et_content.clearFocus();
}
 
源代码4 项目: FimiX8-RE   文件: X8FcExpSettingController.java
public void onError(EditText v, int errorCode, String errorMsg) {
    X8ToastUtil.showToast(this.mContext, this.contentView.getContext().getString(R.string.x8_fc_exp_error_tip), 0);
    double curValue = 0.0d;
    int i = v.getId();
    if (i == R.id.edt_to_up_down) {
        curValue = this.cvToUpDown.getCurValue();
    } else if (i == R.id.edt_to_left_right) {
        curValue = this.cvToLeftRight.getCurValue();
    } else if (i == R.id.edt_to_go_back) {
        curValue = this.cvToGoBack.getCurValue();
    }
    v.setText(String.valueOf(curValue));
    v.clearFocus();
}
 
源代码5 项目: Passbook   文件: HomeActivity.java
public void onConfirm(View view) {
    String password = mPwdEdit.getText().toString();
    if(password.length() < 1) {
        Application.showToast(this, R.string.pwd_wrong, Toast.LENGTH_SHORT);
        return;
    }
    if(mStage == SET_PWD) {
        EditText et_confirm = findViewById(R.id.confirm);
        if(password.equals(et_confirm.getText().toString())) {
            et_confirm.clearFocus();
            InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
            if (imm != null) {
                    imm.hideSoftInputFromWindow(et_confirm.getWindowToken(), 0);
            }
            mApp.setPassword(password, true);
            new InitTask(this).execute();
        }
        else {
            et_confirm.setText("");
            mPwdEdit.setText("");
            Application.showToast(this, R.string.pwd_unmatch, Toast.LENGTH_SHORT);
        }
    }
    else {
        mApp.setPassword(password, false);
        new DecryptTask(mApp.getData(this), mApp.getAppHeaderData(this), this).execute(password);
    }
}
 
源代码6 项目: sealrtc-android   文件: AMUtils.java
public static void onInactive(Context context, EditText et) {

        if (et == null) return;

        et.clearFocus();
        InputMethodManager imm =
                (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
    }
 
源代码7 项目: RxTools-master   文件: RxKeyboardTool.java
/**
 * 动态隐藏软键盘
 *
 * @param context 上下文
 * @param edit    输入框
 */
public static void hideSoftInput(Context context, EditText edit) {
    edit.clearFocus();
    InputMethodManager inputmanger = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputmanger.hideSoftInputFromWindow(edit.getWindowToken(), 0);
}
 
源代码8 项目: Ticket-Analysis   文件: KeyboardUtils.java
/**
 * 动态隐藏软键盘
 */
public static void hideSoftInput(Context context, EditText edit) {
    edit.clearFocus();
    InputMethodManager inputmanger = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputmanger.hideSoftInputFromWindow(edit.getWindowToken(), 0);
}
 
源代码9 项目: Primary   文件: SubjectBaseActivity.java
private void showSoftKeyboard(final EditText view, ViewGroup keypadarea, String defaultInput) {

        view.clearFocus();

        if (defaultInput != null) {
            view.setText(defaultInput);
            view.setSelection(defaultInput.length());
        }
        boolean isnumeric = ((view.getInputType() & InputType.TYPE_CLASS_NUMBER) == InputType.TYPE_CLASS_NUMBER)
                         || ((view.getInputType() & InputType.TYPE_CLASS_DATETIME) == InputType.TYPE_CLASS_DATETIME);

        int whichkeyboard = Integer.parseInt(appPreferences.getString("keyboard_preference", "1"));
        int whichkeypad = Integer.parseInt(appPreferences.getString("keypad_preference", "1"));

        boolean gkeyboardAvail = getResources().getBoolean(R.bool.game_keyboard_available);
        boolean gkeypadAvail = getResources().getBoolean(R.bool.game_keypad_available);

        if (isnumeric && gkeypadAvail && whichkeypad == 1 && keypadarea != null) {
            Keyboard.showNumberpad(this, view, keypadarea, mNumpadkeyMap);

        } else if (!isnumeric && gkeyboardAvail && whichkeyboard == 1 && keypadarea != null) {
            Keyboard.showKeyboard(this, view, keypadarea, mKeyboardkeyMap);

        } else if (whichkeypad == 2 || whichkeyboard == 2 || (isnumeric && !gkeypadAvail) || (!isnumeric && !gkeyboardAvail)) {
            showSystemKeyboard(view);
        }


    }
 
源代码10 项目: sealtalk-android   文件: AMUtils.java
public static void onInactive(Context context, EditText et) {

        if (et == null)
            return;

        et.clearFocus();
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
    }
 
源代码11 项目: medical-data-android   文件: ProfileActivity.java
/**
 * requests focus on a {@link EditText} allowing to see its title too. It is used to set focus
 * on the first question with error.
 *
 * @param et    field we want to set focus in.
 * @param tv_id id of the {@link TextView} which is the title of et.
 */
private void focusFirstError(EditText et, int tv_id) {
    et.clearFocus(); // requestRectangle does not work properly if et is already focused
    et.requestFocus();
    TextView title = (TextView) findViewById(tv_id);
    RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) title.getLayoutParams();
    Rect rect = new Rect(0, -lp.topMargin, title.getWidth(), title.getHeight());
    title.requestRectangleOnScreen(rect);
}
 
源代码12 项目: medical-data-android   文件: RegisterActivity.java
/**
 * requests focus on a {@link EditText} allowing to see its title too. It is used to set focus on the
 * first question with error.
 *
 * @param et    field we want to set focus in.
 * @param tv_id id of the {@link TextView} which is the title of et.
 */
private void focusFirstError(EditText et, int tv_id) {
    et.clearFocus(); // requestRectangle does not work properly if et is focused
    et.requestFocus();
    TextView title = (TextView) findViewById(tv_id);
    RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) title.getLayoutParams();
    Rect rect = new Rect(0, -lp.topMargin, title.getWidth(), title.getHeight());
    title.requestRectangleOnScreen(rect);
}
 
private void updateRegistrationID(String value) {
    EditText editRegistrationID = findViewById(R.id.editRegistrationID);
    editRegistrationID.setText(value);
    editRegistrationID.clearFocus();
}
 
private void updatePushToken(String value) {
    EditText editPushToken = findViewById(R.id.editPushToken);
    editPushToken.setText(value);
    editPushToken.clearFocus();
}
 
@Override
protected void onCreate(Bundle arg0) {
    setTheme(App.theme.theme);
    super.onCreate(arg0);
    setContentView(R.layout.activity_file_editor);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    Bundle b = getIntent().getExtras();
    if (b == null) {
        finish();
        return;
    }
    Picasso.with(this).load(b.<Uri>getParcelable(PreferencesFragment.ARG_ICON_URI)).error(R.drawable.ic_launcher).into((android.widget.ImageView) findViewById(android.R.id.home));

    mFile = b.getString(PreferencesFragment.ARG_FILE);
    mTitle = Utils.extractFileName(mFile);
    mPackageName = b.getString(PreferencesFragment.ARG_PACKAGE_NAME);
    mEditText = (EditText) findViewById(R.id.editText);
    //Hack to prevent EditText to request focus when the Activity is created
    mEditText.post(new Runnable() {
        @Override
        public void run() {
            mEditText.setFocusable(true);
            mEditText.setFocusableInTouchMode(true);
        }
    });

    if (arg0 == null) {
        mEditText.setText(Utils.readFile(mFile));
        mColorTheme = ColorThemeEnum.valueOf(PreferenceManager.getDefaultSharedPreferences(this).getString(KEY_COLOR_THEME, ColorThemeEnum.ECLIPSE.name()));
        setXmlFontSize(XmlFontSize.generateSize(PreferenceManager.getDefaultSharedPreferences(this).getInt(KEY_FONT_SIZE, XmlFontSize.MEDIUM.getSize())));
    } else {
        mHasContentChanged = arg0.getBoolean(KEY_HAS_CONTENT_CHANGED, false);
        mNeedUpdateOnActivityFinish = arg0.getBoolean(KEY_NEED_UPDATE_ON_ACTIVITY_FINISH, false);
        if (mNeedUpdateOnActivityFinish) {
            setResult(RESULT_OK);
        }
        mColorTheme = ColorThemeEnum.valueOf(arg0.getString(KEY_COLOR_THEME));
        setXmlFontSize(XmlFontSize.generateSize(arg0.getInt(KEY_FONT_SIZE)));
    }
    mXmlColorTheme = XmlColorTheme.createTheme(getResources(), mColorTheme);

    updateTitle();
    invalidateOptionsMenu();

    highlightXMLText(mEditText.getText());

    mEditText.clearFocus();
}
 
源代码16 项目: Android   文件: SystemUtil.java
/**
 * Hide the keyboard
 * @param context
 * @param editText
 */
public static void hideKeyBoard(Context context,EditText editText){
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
    editText.clearFocus();
}
 
源代码17 项目: DistroHopper   文件: HomeActivity.java
public void closeDash ()
{
	if (! this.isDashOpened) {
		return;
	}

	if (modeCustomise)
	{
		Intent intent = this.getIntent ();
		intent.putExtra ("customise", false);
		
		this.finish ();
		this.startActivity (intent);
		
		return;
	}
	
	EditText etDashSearch = this.viewFinder.get(R.id.etDashSearch);

	this.llDash.setVisibility (View.GONE);
	this.wpWallpaper.unblur ();
	etDashSearch.setText ("");
	etDashSearch.clearFocus ();

	if (this.getResources ().getInteger (HomeActivity.theme.panel_close_location) != -1)
		this.ibPanelDashClose.setVisibility (View.INVISIBLE);
	
	SharedPreferences prefs = this.getSharedPreferences ();
	this.llPanel.setAlpha ((float) prefs.getInt (Preference.PANEL_OPACITY.getName(), 100) / 100F);

	if (this.getResources ().getBoolean (HomeActivity.theme.panel_background_dynamic_when_dash_opened))
	{
		this.llPanel.setBackgroundResource (HomeActivity.theme.panel_background);

		if (Build.VERSION.SDK_INT >= 19)
		{
			LinearLayout llStatusBar = this.viewFinder.get(R.id.llStatusBar);
			llStatusBar.setBackgroundColor (this.getResources ().getColor (android.R.color.black));
		}
	}


	InputMethodManager imm = (InputMethodManager) this.getSystemService (Context.INPUT_METHOD_SERVICE);
	if (imm != null)
		imm.hideSoftInputFromWindow (this.getWindow ().getDecorView ().getRootView ().getWindowToken (), 0);

	this.flWallpaperOverlay.setVisibility (View.VISIBLE);
	this.flWallpaperOverlayWhenDashOpened.setVisibility (View.INVISIBLE);

	this.isDashOpened = false;
}
 
源代码18 项目: emoji-keyboard   文件: SoftKeyboardUtil.java
public static void dismissSoftKeyboard(Context context, EditText editText) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
    editText.clearFocus();
}
 
源代码19 项目: timecat   文件: KeyboardUtil.java
/**
 * 针对于EditText ,失去焦点,隐藏软件盘
 *
 * @param edit
 */
public void hideKeyboard(EditText edit) {
    edit.clearFocus();
    imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
}
 
源代码20 项目: Yuan-SxMusic   文件: CommonUtil.java
/**
 * 关闭软键盘
 *
 * @param mEditText 输入框
 * @param context   上下文
 */
public static void closeKeybord(EditText mEditText, Context context) {
    mEditText.clearFocus();
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
}