ContextThemeWrapper用于设置样式不起作用

时间:2018-12-21 12:27:16

标签: java android styles

我试图通过按按钮以编程方式创建TextInputLayout时分配样式R.style.Widget_MaterialComponents_TextInputLayout_OutlinedBox。但是由于某种原因,该样式不适用。如果我在xml中设置了相同的样式,则一切正常。

addBreakfast.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            addBreakfast.startAnimation(AnimationUtils.loadAnimation(DiaryFoodAdd.this, R.anim.rotate_complete));
            breakfastTIL.add(counterBreakfast, new TextInputLayout(new ContextThemeWrapper(DiaryFoodAdd.this, R.style.Widget_MaterialComponents_TextInputLayout_OutlinedBox), null, 0));
            breakfastTIL.get(counterBreakfast).setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            breakfastET.add(counterBreakfast, new TextInputEditText(DiaryFoodAdd.this));
            breakfastET.get(counterBreakfast).setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            breakfastET.get(counterBreakfast).setHint(getString(R.string.breakfast));
            breakfastTIL.get(counterBreakfast).addView(breakfastET.get(counterBreakfast));
            breakfastLayout.addView(breakfastTIL.get(counterBreakfast));
            counterBreakfast = counterBreakfast + 1;
        }
    });

0 个答案:

没有答案