activity_ui2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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.hanqi.application3.UIActivity2"
android:orientation="vertical"> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="长按触发上下文菜单"
android:id="@+id/bt_changan"/> <ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/pb_1"/> <ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:progress="50"
android:secondaryProgress="70"
android:id="@+id/pb_2"/>
<!--progress 当前进度-->
<!--
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Small"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Large"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Inverse"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Large.Inverse"/>
-->
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="20"
android:secondaryProgress="40"
android:id="@+id/sb_1"/>
<!--<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="6"
android:rating="3"
android:isIndicator="true"/>
numStars 设置几颗星 isIndicator 是否不准修改--> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="点击触发弹出普通对话框"
android:onClick="pt_onClick"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="点击触发弹出单选对话框"
android:onClick="dx_onClick"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="点击触发弹出多选对话框"
android:onClick="ddx_onClick"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="点击触发弹出自定义对话框"
android:onClick="zdy_onClick"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="点击触发弹出进度条对话框"
android:onClick="jdt_onClick"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="点击触发弹出水平进度条对话框"
android:onClick="jdt1_onClick"
/>
</LinearLayout>

activity_ui2.java

package com.hanqi.application3;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.Toast; public class UIActivity2 extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ui2); Button bt_changan=(Button)findViewById(R.id.bt_changan);
// 创建上下文菜单监听
bt_changan.setOnCreateContextMenuListener(this); //bt_changan.setOnContextClickListener();创建监听
//进度条
//final
final ProgressBar pb_1 = (ProgressBar)findViewById(R.id.pb_1);
final ProgressBar pb_2 = (ProgressBar)findViewById(R.id.pb_2);
SeekBar sb_1=(SeekBar)findViewById(R.id.sb_1); sb_1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
//进度被改变
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
pb_2.setProgress(progress);
}
//开始拖动
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
//结束拖动
@Override
public void onStopTrackingTouch(SeekBar seekBar) { pb_2.setProgress(seekBar.getProgress()); if(seekBar.getProgress() == seekBar.getMax())
{
//设置不可见INVISIBLE 占有空间,但是隐藏
//GONE 直接取消
pb_1.setVisibility(View.GONE);
}
else
{
//可见VISIBLE
pb_1.setVisibility(View.VISIBLE);
} }
});
} @Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { menu.add(0, 1, 0, "添加");
menu.add(0, 2, 1, "修改");
menu.add(0, 3, 2, "删除");
SubMenu m = menu.addSubMenu(0, 4, 3, "子菜单"); m.add(0,41,0,"子菜单项1");
m.add(0,42,0,"子菜单项2");
m.add(0,43,0,"子菜单项3"); // MenuInflater mi = getMenuInflater();
// mi.inflate(R.menu.mymenu, menu); super.onCreateContextMenu(menu, v, menuInfo);
} @Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId())
{
case R.id.it2:
Toast.makeText(UIActivity2.this, "触发了添加1功能", Toast.LENGTH_SHORT).show();
break;
case R.id.it1:
Toast.makeText(UIActivity2.this, "触发了删除1功能", Toast.LENGTH_SHORT).show();
break;
} return super.onContextItemSelected(item);
} @Override
//重写 创建选项菜单的方法
public boolean onCreateOptionsMenu(Menu menu) {
//添加菜单项
//纯编码模式
// menu.add(0,1,0,"添加");
// menu.add(0,2,2,"删除");
// menu.add(0,3,1,"修改");
//加载菜单文件模方式
//1.获取一个菜单加载器
MenuInflater mi = getMenuInflater();
mi.inflate(R.menu.mymenu, menu); return super.onCreateOptionsMenu(menu);
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
//item.getTitle() 加载标题
//Toast.makeText(UIActivity2.this, "选中的菜单项是"+item.getTitle(), Toast.LENGTH_SHORT).show();
//根据菜单项的不同相应不同的功能
//获取Item的id
switch (item.getItemId())
{
case 1: Toast.makeText(UIActivity2.this, "触发了添加功能", Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(UIActivity2.this, "触发了删除功能", Toast.LENGTH_SHORT).show();
break;
case 3:
Toast.makeText(UIActivity2.this, "触发了修改功能", Toast.LENGTH_SHORT).show();
break; case R.id.it1:
Toast.makeText(UIActivity2.this, "触发了添加1功能", Toast.LENGTH_SHORT).show();
break;
case R.id.it2:
Toast.makeText(UIActivity2.this, "触发了删除1功能", Toast.LENGTH_SHORT).show();
break;
} return super.onOptionsItemSelected(item);
}
public void pt_onClick(View v)
{
// //构建一个普通对话框
// //对话框的构建器
// AlertDialog.Builder ab = new AlertDialog.Builder(this);
// ab.setTitle("数据删除");
// ab.setMessage("你确定要删除码?");
// //负面按钮
// ab.setNeutralButton("取消",null);
// //正面按钮
// ab.setPositiveButton("确定", new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// Toast.makeText(UIActivity2.this, "删除成功", Toast.LENGTH_SHORT).show();
// }
// });
//
// ab.show();
//方法连调用 new AlertDialog.Builder(this)
.setTitle("确认保存")
.setMessage("你真的要保存吗?")
.setNeutralButton("取消",null)
.setPositiveButton("保存",null)
.show(); }
public void dx_onClick(View v)
{
final String[] str_color={"红","绿","黄","蓝"};
new AlertDialog.Builder(this)
.setTitle("请选择颜色")
.setSingleChoiceItems(str_color, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(UIActivity2.this, "选中了"+str_color[which], Toast.LENGTH_SHORT).show();
//移除
//dialog.dismiss();
}
})
.setNeutralButton("确定",null) .show();
}
public void ddx_onClick(View v)
{
final String[] str_color={"红","绿","黄","蓝"}; final boolean[] bl_xz = {true,false,false,true};
new AlertDialog.Builder(this)
.setTitle("请选择颜色")
.setMultiChoiceItems(str_color, bl_xz, new DialogInterface.OnMultiChoiceClickListener() {
@Override
//是否选中isChecked
public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) {
Toast.makeText(UIActivity2.this, str_color + "被选中", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(UIActivity2.this, str_color + "取消选中", Toast.LENGTH_SHORT).show();
}
}
}) .setNeutralButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) { //遍历
for (boolean b : bl_xz) { Toast.makeText(UIActivity2.this, "值= " + b, Toast.LENGTH_SHORT).show();
}
}
}) .show();
} public void zdy_onClick(View v)
{
//1.获取加载器
// LayoutInflater lif = getLayoutInflater();
//2.用加载器加载文件
//final View v_1 = lif.inflate(R.layout.loginlayout, null); new AlertDialog.Builder(this)
.setView(R.layout.loginlayout)
//.setView(v_1)
.setNeutralButton("取消", null)
.setPositiveButton("登陆", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) { AlertDialog al = (AlertDialog) dialog;
//处理数据 EditText et_username = (EditText) al.findViewById(R.id.et_username);
Toast.makeText(UIActivity2.this, "用户名=" + et_username.getText(), Toast.LENGTH_SHORT).show(); }
}) .show();
} public void jdt_onClick(View v)
{
ProgressDialog pd = new ProgressDialog(this);
pd.setMessage("正在加载,请稍候...");
// pd.setTitle("进度对话框");
pd.show();
//创建Thread实例重写run(),start()启动多线程
new Thread()
{
@Override
public void run() {
super.run();
try {
Thread.sleep(3000);
}
catch (Exception e)
{ }
}
}.start();
// try {
// Thread.sleep(2000);
// }
// catch (Exception e)
// {
//
// }
//
//
// pd.dismiss();//关闭 //多线程 }
public void jdt1_onClick(View v)
{
final ProgressDialog pd = new ProgressDialog(this);
pd.setMessage("正在加载..."); pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.show();
//创建Thread实例重写run(),start()启动多线程
new Thread()
{
@Override
public void run() {
super.run(); for (int i = 0; i <= pd.getMax();i++)
{
try {
Thread.sleep(300);
}
catch (Exception e)
{ }
pd.setProgress(i);
}
}
}.start(); }
}

andorid 对话框的更多相关文章

  1. andorid 全部对话框

    .xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...

  2. Dialog详解(包括进度条、PopupWindow、自定义view、自定义样式的对话框)

    Dialog详解(包括进度条.PopupWindow.自定义view.自定义样式的对话框)   Android中提供了多种对话框,在实际应用中我们可能会需要修改这些已有的对话框.本实例就是从实际出发, ...

  3. Cordova webapp实战开发:(5)如何写一个Andorid下自动更新的插件?

    在 <Cordova webapp实战开发:(4)Android环境搭建>中我们搭建好了开发环境,也给大家布置了调用插件的预习作业,做得如何了呢?今天我们来学一下如何自己从头建立一个And ...

  4. 代码可读性艺术在Andorid中的体现

    前言 最近接手的一些项目,不同的人编码风格迥异,类里的变量.方法的定义穿插,注释极为稀少,更有一些变量和方法的命名非常近似,例如表示播放队列的"playQueue"和表示歌单的&q ...

  5. 一步步开发自己的博客 .NET版(10、前端对话框和消息框的实现)

    关于前端对话框.消息框的优秀插件多不胜数.造轮子是为了更好的使用轮子,并不是说自己造的轮子肯定好.所以,这个博客系统基本上都是自己实现的,包括日志记录.响应式布局.评论功能等等一些本可以使用插件的.好 ...

  6. jQuery遮罩层登录对话框

    用户登录是许多网站必备的功能.有一种方式就是不管在网站的哪个页面,点击登录按钮就会弹出一个遮罩层,显示用户登录的对话框.这用方式比较灵活方便.而现在扫描二维码登录的方式也是很常见,例如QQ.微信.百度 ...

  7. Android系统默认对话框添加图片

    开发工具Android Studio 今天公司UI要求软件对话框改成加图片的,以前没有做过,所以就学习了一下,废话不多说, 看效果: 创建XML文件dialog_lsit_item.xml <L ...

  8. Android—关于自定义对话框的工具类

    开发中有很多地方会用到自定义对话框,为了避免不必要的城府代码,在此总结出一个工具类. 弹出对话框的地方很多,但是都大同小异,不同无非就是提示内容或者图片不同,下面这个类是将提示内容和图片放到了自定义函 ...

  9. 使用CSS3的box-shadow实现双透明遮罩层对话框

    box-shadow介绍 在我之前的一篇文章<从天猫和支付宝身上学习opcity与rgba>中,介绍了实现双透明遮罩层效果的两种方法,分别是opacity和rgba.他们需要分别依赖于不同 ...

随机推荐

  1. java程序员到底该不该了解一点算法(一个简单的递归计算斐波那契数列的案例说明算法对程序的重要性)

    为什么说 “算法是程序的灵魂这句话一点也不为过”,递归计算斐波那契数列的第50项是多少? 方案一:只是单纯的使用递归,递归的那个方法被执行了250多亿次,耗时1分钟还要多. 方案二:用一个map去存储 ...

  2. Python基础学习Day7 基础数据类型的扩展 集合 深浅copy

    一.基础数据类型的扩展 1.1GBK ---> UTF - 8 # str --->bytes s1 = '太白' # 字符串是unicode编码 b1 = s1.encode('gbk' ...

  3. BOM进IN_BOM_HEADER表后被过滤掉

    1.查看如下两个表发现BOM被过滤掉了 SELECT  PRODUCT_ID||'_'||substr(BOM_ID,1,8),A.* FROM IN_BOM_HEADER A WHERE A.PRO ...

  4. EVIL TWIN AP

    git clone https://github.com/P0cL4bs/3vilTwinAttacker.git cd 3vilTwinAttacker/ ./installer.sh --inst ...

  5. 下载安装windows版Redis

    链接       https://github.com/MicrosoftArchive/redis/releases 选择版本下载 在redis目录打开cmd命令输入 redis-server.ex ...

  6. Python 豆瓣日记爬取

    无聊写了个豆瓣日记的小爬虫,requests+bs4. cookies_src可填可不填,主要是为了爬取仅自己可见的日记. url填写的是日记页面,即https://www.douban.com/pe ...

  7. C# 写App.config配置文件的方法

    private static void AccessAppSettings() { //获取Configuration对象 Configuration config = ConfigurationMa ...

  8. git和svn的对比

  9. 数位dp poj1850

    题目链接:https://vjudge.net/problem/POJ-1850 这题我用的是数位dp,刚刚看了一下别人用排列组合,我脑子不行,想不出来. 在这题里面我把a看成1,其他的依次递增,如果 ...

  10. delet[] 和delete

    string *stringPtr1 = new string; string *stringPtr2 = new string[100]; …… delete stringPtr1; delete ...