鱼C论坛

 找回密码
 立即注册
查看: 2127|回复: 0

[学习笔记] android编程3.2.6

[复制链接]
发表于 2017-9-26 06:36:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
修改activity_main.xml文件
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:orientation="vertical"
  4.     android:layout_height="match_parent"
  5.     android:layout_width="match_parent">
  6.     <ProgressBar
  7.         android:id="@+id/progress_bar"
  8.         android:layout_width="match_parent"
  9.         android:layout_height="60dp"
  10.         style="?android:attr/progressBarStyleHorizontal"
  11.         android:max="100"
  12.         />
  13.     <Button
  14.         android:id="@+id/button"
  15.         android:layout_width="match_parent"
  16.         android:layout_height="wrap_content"
  17.         android:text="button"/>
  18.     <Button
  19.         android:id="@+id/button1"
  20.         android:layout_width="match_parent"
  21.         android:layout_height="wrap_content"
  22.         android:text="alertDialog"/>
  23. </LinearLayout>
复制代码

修改mainactivity.java文件
  1. package com.example.xinwei.viewcontroller2;

  2. import android.content.DialogInterface;
  3. import android.support.v7.app.AlertDialog;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.ProgressBar;

  9. public class MainActivity extends AppCompatActivity {
  10.     private Button button;
  11.     private Button button1;
  12.     private ProgressBar progressBar;
  13.     @Override
  14.     protected void onCreate(Bundle savedInstanceState) {
  15.         super.onCreate(savedInstanceState);
  16.         setContentView(R.layout.activity_main);
  17.         makeProgressBarMove();
  18.         runAlertDialog();
  19.     }

  20.     private void runAlertDialog() {
  21.         button1 = (Button)findViewById(R.id.button1);
  22.         button1.setOnClickListener(new View.OnClickListener() {
  23.             @Override
  24.             public void onClick(View view) {
  25.                 AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
  26.                 alertDialog.setMessage("Something important.");
  27.                 alertDialog.setTitle("this is a Dialog");
  28.                 alertDialog.setCancelable(false);
  29.                 alertDialog.setPositiveButton("ok", new DialogInterface.OnClickListener() {
  30.                     @Override
  31.                     public void onClick(DialogInterface dialogInterface, int i) {

  32.                     }
  33.                 });
  34.                 alertDialog.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
  35.                     @Override
  36.                     public void onClick(DialogInterface dialogInterface, int i) {

  37.                     }
  38.                 });
  39.                 alertDialog.show();
  40.             }
  41.         });
  42.     }

  43.     private void makeProgressBarMove() {
  44.         button = (Button)findViewById(R.id.button);
  45.         progressBar =(ProgressBar)findViewById(R.id.progress_bar);
  46.         button.setOnClickListener(new View.OnClickListener() {
  47.             @Override
  48.             public void onClick(View view) {
  49.                 int progress=progressBar.getProgress();
  50.                 progressBar.incrementProgressBy(5);
  51.                 if(progress==100){
  52.                     progressBar.setVisibility(View.GONE);
  53.                 }
  54.             }
  55.         });
  56.     }
  57. }
复制代码

因为progressDialog控件已经过时,而且代码很简单就不说了,效果图:
assdsd.png

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-20 07:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表