android 显示自定义视图对话框
2016-07-18 00:06
507 查看
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="自定义视图对话框"
android:id="@+id/btnCustomViewDialog"
/>
</LinearLayout>
dialog_custom.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading...."/>
</LinearLayout>
MainActivity.java:
this.findViewById(R.id.btnCustomViewDialog).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("自定义视图");
View view = View.inflate(MainActivity.this,R.layout.dialog_custom,null);
builder.setView(view);
builder.show();
}
});
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="自定义视图对话框"
android:id="@+id/btnCustomViewDialog"
/>
</LinearLayout>
dialog_custom.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading...."/>
</LinearLayout>
MainActivity.java:
this.findViewById(R.id.btnCustomViewDialog).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("自定义视图");
View view = View.inflate(MainActivity.this,R.layout.dialog_custom,null);
builder.setView(view);
builder.show();
}
});
相关文章推荐
- 最新基于高德地图的android进阶开发(1)获取 Map API Key
- 关于Android Studio你可能不知道的10件小事
- Android Studio自定义模板
- 深入浅出Android打包
- 不需要权限的获取蓝牙mac地址方法
- Android fastjson和Realm的完美结合,有坑
- Android编程之自定义数字键盘(原创)
- Android动画之属性动画
- android为按钮事件进行监听过程
- 如何让Android Studio的智能感知不区分大小写?
- Android 基于LocalSocket实现本地多媒体流式播放
- Android,相关学习,20160514
- Android Studio 无法编译,出现下列错误提示的解决方案。
- 我会的android技术总结
- android,获取当前时间。24小时。
- Android,获取当前手机号
- android,rom,厨房环境搭建
- android,锁屏控制音乐
- android,扫描雷达,新浪威盾 笔记
- android,获取当前手机播放的音乐信息