相关疑难解决方法(0)

自定义EditText未在焦点上显示键盘

我正在创建一个自定义的EditText类,因为我需要设置一些自定义字体; 但是现在当我点击editText时,android键盘不再弹出...

这是我的班级:

    package ro.gebs.captoom.utils.fonts;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import ro.gebs.captoom.R;

public class CustomFontEditText extends EditText {

    private Context context;

    public CustomFontEditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        if (!isInEditMode()) {
            TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomFontEditText,
                    defStyle, 0);

            assert a != null;
            int fontId = a.getInteger(R.styleable.CustomFontEditText_fontNameEdit, -1);
            if (fontId == -1) {
                throw new IllegalArgumentException("The font_name attribute is required and must refer "
                        + "to a valid …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view android-input-method android-edittext

20
推荐指数
1
解决办法
8191
查看次数

自定义Android pin码输入小部件

我正在尝试为android创建一个自定义pin代码小部件,作为仅使用EditText带有密码inputType属性的替代方法.我想要显示的是一排盒子,并在用户键入其针脚时填充每个盒子.

其他人做了类似这样的事情,但事实证明这是一个固定数量的EditText视图,并且当字符被输入或删除时,有很多丑陋的代码用于交换焦点.这不是我想采取的方法; 相反,我正在设计我的可定制长度(简单)并且表现为单一的可聚焦视图(不那么容易).

到目前为止,我的概念是LinearLayout(保持"盒子")和EditText(存储用户输入)之间的某种混合.

到目前为止这是代码......

public class PinCodeView extends LinearLayout {
    protected static final int MAX_PIN_LENGTH = 10;
    protected static final int MIN_PIN_LENGTH = 1;

    protected int pinLength;
    protected EditText mText;

    public PinCodeView(Context context, AttributeSet attrs) {
        super(context, attrs);

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PinCodeView);
        try {
            pinLength = a.getInt(R.styleable.PinCodeView_pinLength, 0);
        } finally {
            a.recycle();
        }

        pinLength = Math.min(pinLength, MAX_PIN_LENGTH);
        pinLength = Math.max(pinLength, MIN_PIN_LENGTH);

        setupViews();

        Log.d(TAG, "PinCodeView …
Run Code Online (Sandbox Code Playgroud)

android widget

5
推荐指数
1
解决办法
2万
查看次数