Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在自定义视图上设置内部edittext xml属性_Android_Xml - Fatal编程技术网

Android 在自定义视图上设置内部edittext xml属性

Android 在自定义视图上设置内部edittext xml属性,android,xml,Android,Xml,我创建了一个由EditText和TextView组成的复合视图。。。我想让任何使用我的视图的开发人员都能够做到以下几点 <MyCustomView android:id="@+id/password" android:layout_width="wrap_content" android:layout_height="wrap_content" app:setInputType="textPas

我创建了一个由
EditText
TextView
组成的复合视图。。。我想让任何使用我的视图的开发人员都能够做到以下几点

<MyCustomView
            android:id="@+id/password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:setInputType="textPassword"/>
这行不通。。EditText.setContentType由于某些原因无法工作

我一直在设置其他自定义属性,我的问题是如何设置这个特定的“InputType”似乎不起作用

protected void init(Context context, AttributeSet attrs) {

    if (attrs != null) {
        TypedArray typedArray;
        typedArray = context.obtainStyledAttributes(attrs, R.styleable.ValidateEditText);
        try {
            mHint = typedArray.getString(R.styleable.ValidateEditText_hint);

            mInputType = typedArray.getInt(R.styleable.ValidateEditText_inputType, EditorInfo.TYPE_CLASS_TEXT);
            mMaxLength = typedArray.getInt(R.styleable.ValidateEditText_maxLength, -1);
            mSingleLine = typedArray.getBoolean(R.styleable.ValidateEditText_singleLine, false);
            mPassword = typedArray.getBoolean(R.styleable.ValidateEditText_password, false);
            mImeOption = typedArray.getInt(R.styleable.ValidateEditText_imeOptions, EditorInfo.IME_ACTION_NEXT);
            mEditable = typedArray.getBoolean(R.styleable.ValidateEditText_editable, true);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            typedArray.recycle();
        }
    }
}

@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    //Initialise views
    mErrorMessage = (TextView) findViewById(R.id.error_msg);
        mEditText = (EditText) findViewById(R.id.edit_text);


        mEditText.setInputType(mInputType); 
    ...
}

您可以这样声明可设置样式的属性:

<declare-styleable name="MyCustomView">
    <attr name="android:inputType"/>
</declare-styleable>
int inputType = a.getInt(R.styleable.MyCustomView_android_inputType, EditorInfo.TYPE_NULL);

你可以从

中得到更详细的答案,可能是重复的,不是重复的,我;我更新了我的问题。
int inputType = a.getInt(R.styleable.MyCustomView_android_inputType, EditorInfo.TYPE_NULL);