如何制作颜色微调器以及当我从该微调器中选择一种颜色时更改布局颜色

问题描述

spinner = green yellow black red blue

when i choose blue

  1. 我需要整个布局颜色应该是“蓝色”
  2. 请帮我用 xml 文件和 java 代码构建这个

xml 文件 =

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Spinner
    android:id="@+id/sp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:entries="@array/color_ar" />

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:onClick="ok"
    android:text="set background" />

java 代码 =

公共类 BackgroundSpinner 扩展 AppCompatActivity {

RelativeLayout layout;
Spinner sp;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);

    sp = findViewById(R.id.sp);
    layout = findViewById(R.id.layout);

    layout.setBackgroundColor(Color.RED);
}

public void ok(View view) {

    String a = sp.getSelectedItem().toString();

我在微调器中需要绿色、黄色、黑色、红色、蓝色这些颜色,当我 选择蓝色我需要整个布局颜色应该是蓝色

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)