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

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/haah"
        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"
        android:orientation="vertical"
        tools:context="com.example.dhk.MainActivity" >
        
        <Button
            android:id="@+id/gjm"
            android:layout_width="275dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:text="点击此处可改变背景颜色" />
    
    </LinearLayout>
    package com.example.aaa;
    
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.Button;
    import android.widget.LinearLayout;
    
    public class MainActivity extends Activity implements View.OnClickListener{
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Button wgjm = (Button) findViewById(R.id.gjm);
            wgjm.setOnClickListener(this);
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
            if (id == R.id.action_settings) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }
        String color;
        @Override
        public void onClick(View v) {
            
            // TODO Auto-generated method stub
                AlertDialog dialog;
                AlertDialog.Builder builder = new AlertDialog.Builder(this)
                .setTitle("设置字体大小") //设置标题
                .setIcon(R.drawable.ic_launcher)
                .setSingleChoiceItems(new String[]{"black", "purple", "red", "pink",
                "blue"}, 1,new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                // 点单选按钮时发生的事件,这里which表示你点的单选按钮是第几个
                    switch (which) {
                    case 0:
                        color="#000000";
                        break;
                    case 1:
                        color="#d200d2";
                        break;
                    case 2:
                        color="#ff2d2d";
                        break;
                    case 3:
                        color="#ff60af";
                        break;
                    default:
                        color="#3385ff";
                        break;
                    }
                    
                }
                })
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                //点确定按钮时发生的事件
                    (findViewById(R.id.haah)).setBackgroundColor(Color.parseColor(color));
                    
                }
                })//添加“确定”按钮
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                }
                });
                dialog = builder.create();
                dialog.show();
            }
        }

  • 相关阅读:
    解读《TCP/IP详解》(卷1):05章:RARP(逆地址解析协议)
    Android中利用“反射”动态加载R文件中的资源
    “骆驼”怎么写
    eclipse无法访问genymotion模拟器下/data/data文件解决方案
    解读《TCP/IP详解》(卷1):03章:IP(网际协议)
    解读《TCP/IP详解》(卷1):02章:链路层
    hdu1039 java正则表达式解法
    hdu1027 又是next_permutaiton
    hdu1261 java水过高精度排列组合。。
    hdu1716 STL next_permutation函数的使用
  • 原文地址:https://www.cnblogs.com/gjm717/p/11592010.html
Copyright © 2011-2022 走看看