在自定义组件时,从已有组件源码中会很大收获。
就拿progressDialog来说
     间接父类是dialog,想了解dialog继承结构可以去百度,或者
    从构造器来说ProgressDialog(Context context, int theme)很明显需要个样式主题文件,我们可以在value文件下自定义一个样式文件。
   从外观上需要个动态效果控件和文本框两个属性
    ProgressBar mProgress;   TextView mMessageView
源码中onCreate()方法中 有
     View view = inflater.inflate(R.layout.alert_dialog_progress, null);//来加载布局文件
     setView(view);
    动态效果是由ProgressBar实现,当然我们可以通过给图片添加动态效果也可以实现类似功能,这就需要个anim文件
从上可以总结出创建自定义dialog需要的步骤
 1.继承dialog
 2.一个主题样式文件
 3.一个布局文件来加载
 4.一个anim文件

代码:public class IphoneProgersssDialog extends Dialog {
   private Context context;
   private ImageView img;
   private TextView txt;
       public IphoneProgersssDialog(Context context) {
               super(context, R.style.iphone_progress_dialog);
               this.context=context;
               //加载布局文件
               LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
               View  view=inflater.inflate(R.layout.iphone_progress_dialog, null); 
               img=(ImageView) view.findViewById(R.id.iphone_progress_dialog_img);
               txt=(TextView) view.findViewById(R.id.iphone_progress_dialog_txt);
               //给图片添加动态效果
               Animation anim=AnimationUtils.loadAnimation(context, R.anim.progressbar);
               img.setAnimation(anim);
               txt.setText(R.string.iphone_progressbar_dialog_txt);
               //dialog添加视图
               setContentView(view);

}

public void setMsg(String msg){
               txt.setText(msg);
       }
       public void setMsg(int msgId){
               txt.setText(msgId);
       }

}

看了下pregeressdialog中像activity类一样都有生命周期函数,其实dialog和activity都是窗体概念并不是api中window类,有个地方还是不明白,希望哪位以后版主有针对setcontentview 和setview的话题。
  现在我们就做个iphone风格的进度条吧!

1.继承
    public class IphoneProgersssDialog extends Dialog 
2.定义主题样式 
   在value资源文件下
    <style name="iphone_progress_dialog" parent="@android:style/Theme.Dialog">
     <item name="android:windowFrame">@null</item> <!--Dialog的windowFrame框为无--> 
     <item name="android:windowIsFloating">true</item><!-- 是否漂现在activity上-->
     <item name="android:windowIsTranslucent">true</item><!-- 是否半透明 -->
     <item name="android:windowNoTitle">true</item>
     <item name="android:backgroundDimEnabled">false</item><!-- dim:模糊的 阴影效果 -->
     <item name="android:windowBackground">@drawable/load_bg</item><!-- 背景图片的大小也影响窗口的大小 -->
   </style>

在构造器中   super(context, R.style.iphone_progress_dialog);
3.定义动画文件  progressbar.xml
  <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
   android:shareInterpolator="false" >
<rotate 
       android:interpolator="@android:anim/linear_interpolator"
       android:pivotX="50%"
       android:pivotY="50%"
       android:fromDegrees="0"
       android:toDegrees="+360"
       android:duration="1000"
       android:startOffset="-1"
       android:repeatMode="restart"
       android:repeatCount="-1"/>

</set>
给图片加载动画
Animation anim=AnimationUtils.loadAnimation(context, R.anim.progressbar);
 img.setAnimation(anim);

最后就是setContentview;没有去分析setView的区别

图片不晓得我只上传不了,也许是浏览器的原因吧。

使用方法:

new IphoneProgersssDialog ().show();

Android创建自定义dialog方法详解-样式去掉阴影效果的更多相关文章

  1. Android源码下载方法详解

    转自:http://www.cnblogs.com/anakin/archive/2011/12/20/2295276.html Android源码下载方法详解 相信很多下载过内核的人都对这个很熟悉 ...

  2. Android -- TextView、button方法详解(1)

    1.TextView常规方法 TextView myTextView=null; //声明变量 myTextView=(TextView)findViewById(R.id.myTextView); ...

  3. Android SDK离线安装方法详解(加速安装) 转

    AndroidSDK在国内下载一直很慢··有时候通宵都下不了一点点,最后只有选择离线安装,现在发出离线安装地址和方法,希望对大家有帮助! 离线安装包下载地址:http://dl.vmall.com/c ...

  4. 【转】Android 创建AVD各参数详解

    一.Eclipse中图形创建AVD: Device: 即设备,指具体的手机设备型号,可以在window->Android Virtual Device Manager->Device De ...

  5. Android SDK离线安装方法详解(加速安装)

    AndroidSDK在国内下载一直很慢··有时候通宵都下不了一点点,最后只有选择离线安装,现在发出离线安装地址和方法,希望对大家有帮助 一,首先下载SDK的安装包,android-sdk_r10-wi ...

  6. Android中的onWindowFocusChanged()方法详解

    Android中获取手机屏幕的高度和宽度,我们知道在onCreate方法中获取到的值都是为0的,有人说可以在onClick方法中获取值,这个也是个方法 ,但在onWindowFocusChanged方 ...

  7. android开发之onCreate( )方法详解

    这里我们只关注一句话:This is where you should do all of your normal static set up.其中我们只关注normal static,normal: ...

  8. android之Activity.startManagingCursor方法详解

    在使用数据库操作查询数据后,如果是在Activity里面处理,那么很可能就会用到startManagingCursor()方法,在这里讲一下它的作用和使用注意事项. 调用这个方法,就是将获得的Curs ...

  9. Android -- TextView、button方法详解(2)

    1. button按下状态的改变 Button bt1 = null; // 声明按钮对象 bt1 = (Button) findViewById(R.id.button1); // 获取按钮对象 b ...

随机推荐

  1. 黄聪:如何开启IIS7以上的“IIS6管理兼容性”

    护卫神PHP套件的安装,需要开启“IIS6管理兼容性”, 那么,如何开启IIS7.IIS7.5.IIS8.0的IIS6兼容模式呢? 设置的时候,请参照如下截图:

  2. 黄聪:WordPress 多站点建站教程(六):使用WP_Query、switch_to_blog函数实现获取子站点分类中的文章

    首先在你使用主题的funtions.php里面添加下代码: //根据时间显示最新的分类文章内容,每个站点显示一篇内容 //$blog_id 子站点ID //$catid 分类ID wp_reset_q ...

  3. Skip StyleCop Warnings.

    [SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMust ...

  4. HDU 2176 取(m堆)石子游戏(Nim)

    取(m堆)石子游戏 题意: Problem Description m堆石子,两人轮流取.只能在1堆中取.取完者胜.先取者负输出No.先取者胜输出Yes,然后输出怎样取子.例如5堆 5,7,8,9,1 ...

  5. about_并查集

    前天刚学了并查集,挺好用的,虽然我现在只会用它来解决是不是亲戚啊,是不是朋友啊,带权并查集还不是很理解. 并查集也叫做不相交集合,主要有3个操作,初始化,查找,合并. 并查集其中一个很大的应用就是kr ...

  6. SQL语句的Select部分只写必要的列

    如果Select部分包含不需要的列,这会强制DB2必须进入数据页来得到所请求的特定列,这就要求更多的I/O操作.另外,如果再对这个不需要的列进行排序,就需要创建和传递一个更大的排序文件,相应地会使排序 ...

  7. ylbtech-dbs:ylbtech-PurpleBill(票据管理系统)

    ylbtech-dbs:ylbtech-PurpleBill(票据管理系统) -- =============================================-- DatabaseNa ...

  8. gerrit 配置 apache2 反向代理(转载)

    Apache 2 Configuration To run Gerrit behind an Apache server using mod_proxy, enable the necessary A ...

  9. linux 查看占用端口并kill掉

    主要可以使用ps  命令 或 netstat 命令 weihong@data1:~/jd_parser/jd_parser$ ps aux | head USER PID %CPU %MEM VSZ ...

  10. 新建一个mybatis HelloWorld

    1.下载mybatis https://github.com/mybatis/mybatis-3/ 没有梯子好像打不开 下载一个最新版本,我这里下载的是mybatis-3.4.1.zip 里面有myb ...