第五次作业


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/main_layout"
   >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp"
        android:text="点击按钮改变背景颜色"
        />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Button" />

</RelativeLayout>
复制代码
复制代码
package cn.itcase.backcolor;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private  Button button;
int textSize=1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button=(Button)findViewById(R.id.button);
        button.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        AlertDialog dialog;
        AlertDialog.Builder builder = new AlertDialog.Builder(this)
                .setTitle("设置背景颜色")           //设置标题
                .setIcon(R.drawable.ic_launcher)
                .setSingleChoiceItems(new String[]{"红色", "白色", "黑色", "蓝色",
                        "黄色"},textSize,new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        if (which==0){
                            ((RelativeLayout)findViewById(R.id.main_layout)).setBackgroundColor(Color.parseColor("#ff0000"));
                        }
                        else if(which==1){
                            ((RelativeLayout)findViewById(R.id.main_layout)).setBackgroundColor(Color.parseColor("#ffffff"));
                        }
                        else if(which==2){
                            ((RelativeLayout)findViewById(R.id.main_layout)).setBackgroundColor(Color.parseColor("#000000"));
                        }
                        else if(which==3){
                            ((RelativeLayout)findViewById(R.id.main_layout)).setBackgroundColor(Color.parseColor("#0000fb"));
                        }
                        else {
                            ((RelativeLayout)findViewById(R.id.main_layout)).setBackgroundColor(Color.parseColor("#f1ff00"));
                        }
                    }
                })
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
//                        ((RelativeLayout)findViewById(R.id.main_layout)).setBackgroundColor(Color.parseColor("#3FE2C5"));
                        dialog.dismiss();
                    }
                })//添加“确定”按钮
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        dialog = builder.create();
        dialog.show();

    }
}

优质内容筛选与推荐>>
1、文件上传到ftp服务工具类
2、LA2218 Triathlon /// 半平面交 oj22648
3、eclipse新建的maven项目没有web-Inf目录
4、日历控件的使用
5、分块查找算法


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号