EditText没有拾取defStyleRes

时间:2019-06-15 02:02:16

标签: java android

基本上,当我通过代码添加新的EditText时,它不会应用我分配的defStyleRes并变得无法对焦。但是,如果我不给它分配defStyleRes,它就可以正常工作。

activity.java

    public void addNewStep(View v) {
        TextView newStepTitle = new TextView(this, null, 0, R.style.RecipeDetailTitle);
        newStepTitle.setText("Step " + (editStepArray.size() + 1));

        //EditText nextEditStep = new EditText(this, null, 0, R.style.RecipeProceduresInputField); -- Style not working for some reason
        EditText nextEditStep = new EditText(this);
        nextEditStep.setTag("editStep" + editStepArray.size());
        nextEditStep.setHint("Tell us about something...");
        editStepArray.add(nextEditStep);

        procedureLayout.addView(newStepTitle);
        procedureLayout.addView(nextEditStep);
    }

style.xml

    <style name="RecipeProceduresInputField">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:hint">Tell us how to make this.</item>
    </style>

0 个答案:

没有答案