zoukankan      html  css  js  c++  java
  • 第五次作业

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/rl1"
        tools:context=".MainActivity">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮"
            android:textSize="39sp"
            android:background="#66cccccc"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:onClick="test"
            />
    </RelativeLayout>
    package com.example.five;
    
    import android.content.DialogInterface;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.view.View;
    import androidx.appcompat.app.AlertDialog;
    import androidx.appcompat.app.AppCompatActivity;
    
    public class MainActivity extends AppCompatActivity {
        String[] a = {"#CC3300", "#FFFF00", "#3300FF", "#33CC33", "#9900CC"};
        int b = 0;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
        public void test(View view) {
            AlertDialog dialog;
            AlertDialog.Builder builder = new AlertDialog.Builder(this)
                    .setTitle("设置背景颜色")           //设置标题
                    .setIcon(R.drawable.ic_launcher_background)
                    .setSingleChoiceItems(new String[]{"红色", "黄色", "蓝色", "绿色", "紫色"}, b, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // 点单选按钮时发生的事件,这里which表示你点的单选按钮是第几个
                            b = which;
                        }
                    })
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //点确定按钮时发生的事件
                            findViewById(R.id.rl1).setBackgroundColor(Color.parseColor(a[b]));
                            dialog.dismiss();
                        }
                    })//添加“确定”按钮
                    .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // 点取消按钮发生的事件
                            dialog.dismiss();
                        }
                    });
            dialog = builder.create();
            dialog.show();
    
        }
    
    
    }

     

     

  • 相关阅读:
    Pandas: 如何将一列中的文本拆分为多行? | Python
    Python项目实战:福布斯系列之数据采集
    Python: Pandas运算的效率探讨以及如何选择高效的运算方式
    Pandas数据处理实战:福布斯全球上市企业排行榜数据整理
    从历史来看印度的裂痕和隐忧 | 阅览群书
    Python库:序列化和反序列化模块pickle介绍
    无法加载 DLL“SQLite.Interop.DLL”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。
    spring 问题笔记
    java 大量数据处理问题记录
    spring mvc 整合swagger
  • 原文地址:https://www.cnblogs.com/lixiaoai/p/11580794.html
Copyright © 2011-2022 走看看