设为首页 加入收藏

TOP

Android使用自定义透明Dialog样式的Activity
2014-11-24 07:40:25 来源: 作者: 【 】 浏览:2
Tags:Android 使用 定义 透明 Dialog 样式 Activity

例如这样:


android:theme=”@android:style/Theme.Dialog”>


如果你觉得上面不足以满足你的需求想实现 半透明的, 圆角的,不妨可以试试自定义对话框的style


首先


第一步: 准备工作要做好 一张.9图片


loading_bg.9.png


第二步 :自定义style 在你项目 values 文件夹中创建一个styles.xml 文件


接着在styles文件中添加 名为 MyDialogStyle的style



第三步:Dialog的布局 在layout文件夹中添加布局文件 activity_main.xml


xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">


android:layout_width="180dp"
android:layout_height="180dp"
android:layout_centerInParent="true"
android:background="@drawable/loading_bg" >


android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:orientation="vertical" >


android:id="@+id/progressBar1"
style=" android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />


android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="正在登录"
android:textColor="#fff"
android:textSize="20sp" />




创建 DialogActivity类


public class DialogActivity extends Activity
{


@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 这里你可以进行一些等待时的操作,我这里用8秒后显示Toast代理等待操作
new Handler().postDelayed(new Runnable(){
@Override
public void run(){

DialogActivity.this.finish();
Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_SHORT).show();
}
}, 8000);
}
}



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android开发之自定义属性(Define .. 下一篇Linux kernel探究IO Scheduling

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Libevent C++ 高并发 (2025-12-26 00:49:30)
·C++ dll 设计接口时 (2025-12-26 00:49:28)
·透彻理解 C 语言指针 (2025-12-26 00:22:52)
·C语言指针详解 (经典 (2025-12-26 00:22:49)
·C 指针 | 菜鸟教程 (2025-12-26 00:22:46)