Android自定义布局弹窗
来源:互联网 发布:淘宝好评怎么看不到 编辑:程序博客网 时间:2024/05/17 03:42
弹窗在应用中经常用到,popwindow什么的都太复杂,最近发现了一种简便的弹窗方式,先看图:
废话不多说,上代码:
Activty:
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn = (Button) findViewById(R.id.btn); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showMyDialog(); } }); } /** * 自定义弹窗 */ private void showMyDialog() { LayoutInflater mLayoutInflater = LayoutInflater.from(MainActivity.this); LinearLayout mDialog = (LinearLayout) mLayoutInflater.inflate(R.layout.dialog_layout, null); final Dialog dialog = new AlertDialog.Builder(MainActivity.this).create(); dialog.show(); dialog.getWindow().setContentView(mDialog); mDialog.findViewById(R.id.yes).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "确定", Toast.LENGTH_SHORT).show(); dialog.dismiss(); } }); mDialog.findViewById(R.id.cannel).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_SHORT).show(); dialog.dismiss(); } }); }}> Demo 下载链接http://download.csdn.net/detail/java201159416/9450224****注意:AlertDialog导包是import android.app.AlertDialog, 而不是import android.support.v7.app.AlertDialog;****
0 0
- Android自定义布局弹窗
- android自定义布局
- Android自定义Notification布局
- android 自定义Preferecne布局
- android 自定义Preferecne布局
- android AlertDialog自定义布局
- Android自定义Gallery布局
- 【Android】自定义AlertDialog布局
- android 自定义Layout布局
- Android ListView自定义布局
- android自定义表格布局
- Android自定义布局
- android自定义actionBar布局
- Android 自定义RadioGroup布局
- Android自定义布局
- Android ActionBar 自定义布局
- Android自定义ToolBar布局
- android自定义布局
- 自定义View之刻度盘
- 利用分桶思想实现小范围整数的优先队列
- LinkedList---Delete Node in the Middle of Singly Linked List
- 代理模式
- css hack
- Android自定义布局弹窗
- WCF、WebAPI、WCFREST、WebService之间的区别
- JavaSE学习笔记_10:Java多线程
- svg
- PropertyDescriptor 详解
- iOS开发必备HUD(透明指示层)
- Android 应用程序无缝设计
- 谁将了真话
- unity实现鼠标让物体绕世界Y轴旋转_C#