[英]How can i change backround color for all activities with a button?
我编写的代码不完整,我想更改所有活动的背景颜色。 但是它总是崩溃。 请帮助,我被困住了。 提前致谢!
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);
}
});
}
}
我希望为这2个活动更改backrgound,但是结果最后,我崩溃了。
您可以使用自己的自定义主题。 首先,创建一个主题,然后从Manifest.xml
应用程序范围设置该主题。 喜欢 -
<application
android:theme="@android:style/Theme.Holo"
android:theme="@style/MyTheme">
或者,您可以在Manifest.xml
每个活动中定义主题。
<activity
android:theme="@android:style/Theme.Holo"
android:theme="@style/MyTheme">
如果您想进一步了解android样式和主题,请阅读此文章,直至完整播放列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.