• 第五次作业


     1 <?xml version="1.0" encoding="utf-8"?>
     2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3    android:id="@+id/ly1"
     4     xmlns:app="http://schemas.android.com/apk/res-auto"
     5     xmlns:tools="http://schemas.android.com/tools"
     6     android:layout_width="match_parent"
     7     android:layout_height="match_parent"
     8     tools:context=".MainActivity">
     9 
    10    <Button
    11        android:id="@+id/bt"
    12        android:layout_width="wrap_content"
    13        android:layout_height="wrap_content"
    14        android:text="切换背景颜色"
    15        android:background="#EEE9E9"
    16        android:layout_centerHorizontal="true"
    17        android:layout_centerVertical="true"
    18        android:textColor="#383535">
    19        </Button>
    package com.example.singlechoicedialog;
    import androidx.appcompat.app.AppCompatDialog;
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.RelativeLayout;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
    Button bt;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            inter();
    
            View.OnClickListener bt1 = new bt1();
            bt.setOnClickListener(bt1);
        }
        public void inter() {
            bt = findViewById(R.id.bt);
        }
    
        class bt1 implements View.OnClickListener{
            String bj1="#FFFFFF";
    
            @Override
            public void onClick(View view) {
                AlertDialog dialog;
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
                        .setTitle("设置主题背景")           //设置标题
                        .setIcon(R.drawable.ic_launcher_background)
                        .setSingleChoiceItems(new String[]{"红", "白", "黑", "蓝",
                        },2,new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                // 点单选按钮时发生的事件,这里which表示你点的单选按钮是第几个
                                switch (which){
                                    case 0:bj1="#FFF44336"
                                    ;break;
                                    case 1:bj1="#FFFFFF"
                                    ;break;
                                    case 2:bj1="#000000"
                                    ;break;
                                    case 3:bj1="#FF00BCD4"
                                    ;break;
                                }
    
                            }
                        })
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                //点确定按钮时发生的事件
    
                                ((RelativeLayout)findViewById(R.id.ly1)).setBackgroundColor(Color.parseColor(bj1));
    
                            }
                        })//添加“确定”按钮
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // 点取消按钮发生的事件
                                dialog.dismiss();
                            }
                        });
                dialog = builder.create();
                dialog.show();
    
            }
        }
    }
    

      

  • 相关阅读:
    DIV+CSS列表式布局(同意图片的应用)
    Cache 应用程序数据缓存
    mysql 中 isnull 和 ifnull 判断字段是否为null
    Logo图标快速生成软件(Sothink Logo Maker) v3.5 官方设计师版
    Linqer工具
    mvc学习视频
    MvcPager注意版本与mvc的版本
    此版本的 SQL Server 不支持用户实例登录标志。该连接将关闭“的解决
    ASP.NET 免费开源控件
    逆向知识之CS1.6辅助/外挂专题.1.实现CS1.6主武器副武器无限子弹
  • 原文地址:https://www.cnblogs.com/96111314w/p/11588439.html
Copyright © 2020-2023  润新知