我在styles.xml中将主题更改为深色:
<style name="AppTheme" parent="Theme.AppCompat">
我不确定为什么会这样。现在,这是我的代码的简化版本,重复了该问题:
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;
}
}