Android:一项活动的文字颜色不会采用深色主题

时间:2018-07-02 03:17:50

标签: java android

我在styles.xml中将主题更改为深色:

<style name="AppTheme" parent="Theme.AppCompat">

,这3个活动中的2个似乎调整得很好: enter image description here enter image description here

但随后其他活动调整得不好: enter image description here

我不确定为什么会这样。现在,这是我的代码的简化版本,重复了该问题:

public class WorkoutActivity extends AppCompatActivity {

    public static final String EXTRA_DAY = "blah";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_workout);

        Intent dayNumIntent = getIntent();
        String dayExtra = dayNumIntent.getStringExtra(EXTRA_DAY);

        LayoutParams linearLayoutParams = new LayoutParams(-1, -2, 1);
        LayoutParams exercisePrevParams = new LayoutParams(0, -1, 4);

        TextView topText = findViewById(R.id.dayText);
        topText.setText(dayExtra);

        LinearLayout mLinearLayout = findViewById(R.id.workout_layout);

        LinearLayout statLabelLayout = new LinearLayout(getApplicationContext());
        statLabelLayout.setOrientation(LinearLayout.HORIZONTAL);

        statLabelLayout.addView(defaultTextView(getResources().getString(R.string.previous), 16), exercisePrevParams);
        mLinearLayout.addView(statLabelLayout, linearLayoutParams);

    }

    private TextView defaultTextView (String text, int textSize){
        TextView textView = new TextView(getApplicationContext());
        textView.setText(text);
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(textSize);
        return textView;
    }

}

0 个答案:

没有答案