[英]How can i change backround color for all activities with a button?
I made a code which is not complete and I wanted to change the background color for all activities. 我编写的代码不完整,我想更改所有活动的背景颜色。 But it always crashes. 但是它总是崩溃。 Please help, I'm stuck. 请帮助,我被困住了。 Thanks in advance! 提前致谢!
package com.example.dk199.calculator;
import android.graphics.Color;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
public class DisplayActivity extends AppCompatActivity {
Button b1, b2, b3, b4;
RelativeLayout Rd;
ConstraintLayout Cl;
@Overeride
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);
b1 = (RadioButton) findViewById(R.id.green2);
b4 = (RadioButton) findViewById(R.id.orange2);
b3 = (RadioButton) findViewById(R.id.yellow2);
b4 = (RadioButton) findViewById(R.id.white2);
Rd = (RelativeLayout) findViewById(R.id.DisplayActivity);
Cl = (ConstraintLayout) findViewById(R.id.MainActivity);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Rd.setBackgroundColor(Color.GREEN);
Cl.setBackgroundColor(Color.GREEN);
}
});
}
}
I was hoping to change the backrgound for this 2 activities but end of the result, I got crashes. 我希望为这2个活动更改backrgound,但是结果最后,我崩溃了。
You can use custom theme of your own. 您可以使用自己的自定义主题。 At first, make a theme and then set the theme from application scope in Manifest.xml
. 首先,创建一个主题,然后从Manifest.xml
应用程序范围设置该主题。 Like - 喜欢 -
<application
android:theme="@android:style/Theme.Holo"
android:theme="@style/MyTheme">
Or you can define your theme in every activity from Manifest.xml
. 或者,您可以在Manifest.xml
每个活动中定义主题。
<activity
android:theme="@android:style/Theme.Holo"
android:theme="@style/MyTheme">
If you want to know more about android styling and themeing, read this post upto full playlist. 如果您想进一步了解android样式和主题,请阅读此文章,直至完整播放列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.