• 第五个作业


    package com.example.homework4;
    
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.support.v7.app.ActionBarActivity;
    import android.view.View;
    import android.widget.RelativeLayout;
    
    public class MainActivity extends ActionBarActivity {
        public int i = 0, r = 0, g = 0, b = 0;
        public int[] arr = { Color.rgb(0, 0, 255), Color.rgb(255, 0, 0),
                Color.rgb(255, 255, 255), Color.rgb(0, 0, 0), Color.rgb(0, 255, 0) };
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    
        public void click(View v) {
            AlertDialog dialog;
            AlertDialog.Builder builder = new AlertDialog.Builder(this)
                    .setTitle("设置字体大小")
                    // 设置标题
                    .setIcon(R.drawable.ic_launcher)
                    .setSingleChoiceItems(
                            new String[] { "蓝色", "红色", "白色", "黑色", "绿色" }, 0,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    // 点单选按钮时发生的事件,这里which表示你点的单选按钮是第几个
                                    i = which;
                                }
                            })
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // 点确定按钮时发生的事件
                            RelativeLayout rl = (RelativeLayout) findViewById(R.id.qqq);
                            rl.setBackgroundColor(arr[i]);
    
                        }
                    })
                    .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
            dialog = builder.create();
            dialog.show();
        }
    }
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/qqq"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.homework4.MainActivity" >
    
        <Button
            android:id="@+id/but1"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="188dp"
            android:onClick="click"
            android:text="设置背景颜色" />
    
    </RelativeLayout>

  • 相关阅读:
    修正MYSQL错误数据的一个存储过程
    解决教学平台上文件中存在无扩展名BUG的办法
    使用C#解析XMIND文件格式
    ASPOSE的示例下载地址
    Https所涉及名词及相关后缀名解释
    Https单向认证和双向认证介绍
    转Postman请求Https接口
    About the Apple Captive Network Assistant
    python之numpy的基本使用
    Python Numpy 数组的初始化和基本操作
  • 原文地址:https://www.cnblogs.com/zwcg/p/11569289.html
Copyright © 2020-2023  润新知