• Android第五次作业


    <?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">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="点击下方按钮
    更换背景颜色"
            android:textColor="#ff3300ff"
            android:textSize="35sp"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="150dp"/>
        <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.workfive;
    
    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();
    
        }
    
    
    }

     

     

  • 相关阅读:
    objective c 中基本类型的操作
    [转载]Server.MapPath和Request.MapPath()的用法
    [转载]mstsc远程报:这可能是由于CredSSP 加密Oracle修正的两种完美解决方法
    [转载]忘记token怎么加入k8s集群
    ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded; 的解决办法
    [转载]AutoMapper 9.0的改造
    [转载]k8s注册节点提示Docker SystemdCheck]: detected cgroupfs" as the Docker cgroup dr iver. The r ecommended dr fiver is" systemd"
    [转载]Linux的Vi命令详解
    [转载]查看虚拟机里的Centos7的IP
    [转载]centos关闭swap分区
  • 原文地址:https://www.cnblogs.com/mengjia0513/p/11551006.html
Copyright © 2020-2023  润新知