自定义Dialog
来源:互联网 发布:编程培训机构推荐 编辑:程序博客网 时间:2024/06/05 05:33
工具类:
public class DialogUtil {
@SuppressLint("InlinedApi")public static Dialog createLoadingDialog(Context context) { LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(R.layout.progress_bar, null); LinearLayout layout = (LinearLayout) v.findViewById(R.id.layout); Dialog loadingDialog = new Dialog(context, R.style.loading_dialog_tran); loadingDialog.setCanceledOnTouchOutside(false);// true点击对话框外部取消对话框显示 loadingDialog.setCancelable(false);// 不可以用“返回键”取消 loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); return loadingDialog;}
}
设置基类,添加调用方法:
package com.example.dialogdemo;
import android.app.Dialog;
import android.support.v7.app.ActionBarActivity;
public class baseActionBarActivity extends ActionBarActivity {
/**
* 加载图片提示框
*/
private Dialog progressDialog;
/** * 显示dialog */public void showProgressDialog() { try { if (progressDialog == null) { progressDialog = DialogUtil.createLoadingDialog(this); } progressDialog.show(); } catch (Exception e) { e.printStackTrace(); }}/** * 隐藏dialog */public void dismissProgressDialog() { try { if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } } catch (Exception e) { e.printStackTrace(); }}/** * dialog是否显示 */public boolean isShow() { try { if (progressDialog != null && progressDialog.isShowing()) { return true; } } catch (Exception e) { e.printStackTrace(); } return false;}
}
首页显示:
package com.example.dialogdemo;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends baseActionBarActivity implements OnClickListener {
private Button show, dismiss;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); show = (Button) findViewById(R.id.show); show.setOnClickListener(this); dismiss = (Button) findViewById(R.id.dismiss); dismiss.setOnClickListener(this);}@Overridepublic 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;}@Overridepublic 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);}@Overridepublic void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.show: showProgressDialog(); break; case R.id.dismiss: dismissProgressDialog(); break; default: break; }}
}
下载地址
https://github.com/youlongxifeng/Dialog
0 0
- 自定义Dialog---继承Dialog
- 自定义Dialog android Dialog
- 自定义Dialog
- 自定义Dialog
- 自定义dialog
- 自定义 Dialog
- 自定义dialog
- 自定义 dialog
- 自定义Dialog
- 自定义 Dialog
- 自定义Dialog
- 自定义dialog
- 自定义Dialog
- 自定义 Dialog
- 自定义Dialog
- 自定义Dialog
- 自定义Dialog
- 自定义Dialog
- TortoiseSVN的使用入门
- 字符串的全排列 递归
- Syntax error on token "Invalid Regular Expression Options", no accurate corr
- 使用symbolicatecrash分析iOS Crash文件
- 正则表达式判断字符串是否为MAC地址
- 自定义Dialog
- 一次Redis TTL 为0的问题排查
- git的使用
- storm入门学习中文版
- http://www.w3school.com.cn/b.asp
- 贝塞尔曲线
- Practical Rendering and Computation with Direct3D 11学习笔记(2.1.2)
- asm基础——堆栈框架、调用惯例
- c++基础--容器适配器