<?xml version="1.0" enCoding="utf-8"?><androIDx.constraintlayout.Widget.ConstraintLayout 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:ID="@+ID/bg" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" tools:context=".MainActivity" tools:ignore="InvalIDID"> <button androID:ID="@+ID/bt" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_marginEnd="80dp" androID:layout_marginRight="80dp" androID:layout_marginBottom="408dp" androID:background="#cccccc" androID:onClick="click" androID:text=" Change the background color " androID:textcolor="#ffffff" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" tools:ignore="MissingConstraints,OnClick" /></androIDx.constraintlayout.Widget.ConstraintLayout>
package com.example.myapplication1;import androIDx.appcompat.app.AlertDialog;import androIDx.appcompat.app.AppCompatActivity;import androID.annotation.Suppresslint;import androID.content.DialogInterface;import androID.graphics.color;import androID.os.Bundle;import androID.text.style.BackgroundcolorSpan;import androID.vIEw.VIEw;import androID.Widget.relativeLayout;import androID.Widget.TextVIEw;import androID.Widget.Toast;import java.util.List;public class MainActivity extends AppCompatActivity { @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); } String ba="000000"; public voID click(VIEw vIEw){ AlertDialog dialog; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("color"); builder.setIcon(R.drawable.ic_launcher_background); builder.setSingleChoiceItems(new String[]{"orange", "blue", "pink", "green"}, 0, new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog, int which) { switch(which){ case 0: ba="#ffba8f"; break; case 1: ba="#98caec"; break; case 2: ba="fca0c9"; break; case 3: ba="bbe094"; break; } } }); builder.setPositivebutton("OK", new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog, int which) { (findVIEwByID(R.ID.bg)).setBackgroundcolor(color.parsecolor(ba)); dialog.dismiss(); } }); builder.setNegativebutton("cancel", new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog=builder.create(); dialog.show(); }}
总结
以上是内存溢出为你收集整理的Android 作业05全部内容,希望文章能够帮你解决Android 作业05所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)