@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.countdown_main);
// Show the Up button in the action bar.
setupActionBar();
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Get the message from intent
Intent intent1 = getIntent();
// Create the text view
TextView textView1 = new TextView(this);
textView1.setTextSize(45);
textView1.setText(message);
setContentView(R.layout.countdown_main);
// Set the text view as an activity layout
setContentView(textView1);
}
Why is it that my view from countdown_main.xml isn't being shown directly underneath the setcontentview() ?
I would like the text in textview1 to be shown in the middle of my activity screen on top of my layout in countdown_main.xml .
How do I do this?
SetContentView sets the entire view for your app. It replaces the previous view. If you want to add a view to the screen, the best way would be to put that view in your xml. If you really wanted to add it dynamically, you'd find a ViewGroup (like a LinearLayout or a RelativeLayout) in your xml via findViewById. Then you would add the new view to it as a child view. Make sure to set its layout parameters as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.