我做了一個不完整的代碼,我想更改所有活動的背景顏色。但它總是崩潰。請幫忙,我卡住了。提前致謝!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;@Overerideprotected 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 個活動的背景,但結果是,我遇到了崩潰。
1 回答

胡子哥哥
TA貢獻1825條經驗 獲得超6個贊
您可以使用自己的自定義主題。首先,制作一個主題,然后從應用范圍中設置主題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 樣式和主題的信息,請閱讀這篇文章以獲取完整的播放列表。
添加回答
舉報
0/150
提交
取消