Android进阶学习-自定义主题(3)
效果图,略骚,不要笑!!!
我们使用的是这么一张图片,图片是静态的,我们通过旋转动画去实现加载的效果.
首先我们看下,一个加载窗口需要些什么.一个ImageVIew和一个TextView,那么我们就有了下面的布局文件.load_layout_xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/dialog_view"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"android:minHeight="60dp"android:minWidth="180dp"android:gravity="center"android:padding="10dp"android:background="@drawable/loading_bg"><ImageViewandroid:id="@+id/progressIV"android:layout_width="64dp"android:layout_height="64dp"android:src="@drawable/progress"/><TextViewandroid:id="@+id/tipTV"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:textColor="#eeeeee"android:text="正在加载中,请稍候..." />
</LinearLayout>
其中loading_bg是我们的背景图,这里我们就使用自定义的shape,在drawable目录下添加loading_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"><corners android:radius="10dp" /><gradientandroid:centerColor="#FF4081"android:endColor="#FF4081"android:startColor="#FF4081" />
</shape>
下面开始我们的主代码编写.
package com.example.august.customtheme;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomProgressDialog extends Dialog {/*** 从我们的布局文件loading_layout加载的View*/private View mContentView;/*** 我们的两个小空控件,显示图片和显示文字*/private ImageView mImageView;private TextView mTextView;/*** 我们只去覆写指定主题的方法,并且我们就只有这么一个构造器* @param context* @param themeResId* @param LayoutID* @param imageViewID* @param textViewID*/public CustomProgressDialog(Context context, int themeResId, int LayoutID, int imageViewID, int textViewID) {super(context, themeResId);mContentView = LayoutInflater.from(context).inflate(LayoutID, null);mImageView = (ImageView) mContentView.findViewById(imageViewID);/*** 为图片设置一个旋转动画*/RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);rotateAnimation.setInterpolator(new AccelerateInterpolator());rotateAnimation.setDuration(1500);rotateAnimation.setRepeatCount(-1);mImageView.startAnimation(rotateAnimation);mTextView = (TextView) mContentView.findViewById(textViewID);setContentView(mContentView);}
}
这里我们构造器写那么多参数,只是为了耦性降低一点.可以自己指定其他布局和在后续增加更多方法去实例化这个Dialog.
下面我们就可以去使用了,调用代码如下
CustomProgressDialog mProgressDialog = new CustomProgressDialog(MainActivity.this, R.style.loading_dialog, R.layout.load_layout,R.id.progressIV, R.id.tipTV);mProgressDialog.show();
我们再去给他公布一下方法,去设置那个文本信息和图片,于是乎我们给CustomProgressDialog添加以下方法
public void setMessage(String text) {if (mTextView != null) {mTextView.setText(text);}}public void setProgressBitmap(Bitmap bitmap) {if (mImageView != null) {mImageView.setImageBitmap(bitmap);}}
最后,如果你需要大量使用特定布局对应的ProgressDialog,那么我们还可以去把layout写死,于是又诞生了MyProgressDialog
public class MyProgressDialog {public static CustomProgressDialog get(Context context) {return new CustomProgressDialog(context, R.style.CustomDialog, R.layout.loading_layout, R.id.progressIV,R.id.tipTV);}}
下面我们调用的代码就变得简单了
CustomProgressDialog mProgressDialog = MyProgressDialog.get(MainActivity.this);mProgressDialog.show();
CustomProgressDialog整体代码:
package com.example.august.customtheme;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomProgressDialog extends Dialog {/*** 从我们的布局文件loading_layout加载的View*/private View mContentView;/*** 我们的两个小空控件,显示图片和显示文字*/private ImageView mImageView;private TextView mTextView;/*** 我们只去覆写指定主题的方法,并且我们就只有这么一个构造器* @param context* @param themeResId* @param LayoutID* @param imageViewID* @param textViewID*/public CustomProgressDialog(Context context, int themeResId, int LayoutID, int imageViewID, int textViewID) {super(context, themeResId);mContentView = LayoutInflater.from(context).inflate(LayoutID, null);mImageView = (ImageView) mContentView.findViewById(imageViewID);/*** 为图片设置一个旋转动画*/RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);rotateAnimation.setInterpolator(new AccelerateInterpolator());rotateAnimation.setDuration(1500);rotateAnimation.setRepeatCount(-1);mImageView.startAnimation(rotateAnimation);mTextView = (TextView) mContentView.findViewById(textViewID);setContentView(mContentView);}public void setMessage(String text) {if (mTextView != null) {mTextView.setText(text);}}public void setProgressBitmap(Bitmap bitmap) {if (mImageView != null) {mImageView.setImageBitmap(bitmap);}}
}
转载于:https://my.oschina.net/august1996/blog/656210
Android进阶学习-自定义主题(3)相关推荐
- Android进阶:自定义视频播放器开发(下)
上一篇文章我们主要讲了视频播放器开发之前需要准备的一个知识,TextureView,用于对图像流的处理.这篇文章开始构建一个基础的视频播放器. 一.准备工作 在之前的文章已经说过了,播放器也是一个vi ...
- Android进阶:自定义视频播放器开发(上)
随着快手,抖音,西瓜视频等视频APP的崛起,视频播放已经成为主流,此时作为Android研发的你,想要提高自己的能力还不知道怎么开发视频播放器怎么行?所以今天就带着大家一起开发一个简易播放器:Smal ...
- android java服务,Android进阶学习必会:Java Binder中的系统服务
前言 这个知识点是Android进阶学习必须掌握的知识点之一,也是高阶Android架构师经常问到的点.在这里分想给大家,希望对大家的工作和学习有所帮助.喜欢本文的记得点赞关注哦~ 在前面的Andro ...
- (四)MkDocs学习——自定义主题
mkdocs学习笔记系列 (一)MkDocs 学习--快速开始 (二)MkDocs学习笔记--撰写文档 (三)MkDocs学习--配置主题 (四)MkDocs学习--自定义主题 (五)MkDocs学习 ...
- android进阶知识总结,Android进阶学习有哪些知识点
Android进阶学习有哪些知识点 发布时间:2020-07-29 12:50:39 来源:亿速云 阅读:114 作者:Leah 本篇文章给大家分享的是有关Android进阶学习有哪些知识点,小编觉得 ...
- Android进阶之自定义View实战(二)九宫格手势解锁实现
一.引言 在上篇博客Android进阶之自定义View实战(一)仿iOS UISwitch控件实现中我们主要介绍了自定义View的最基本的实现方法.作为自定义View的入门篇,仅仅介绍了Canvas的 ...
- android设置主题的方法,Android_修改Android App样式风格的方法,android中可以自定义主题和风格 - phpStudy...
修改Android App样式风格的方法 android中可以自定义主题和风格.风格,也就是style,我们可以将一些统一的属性拿出来,比方说,长,宽,字体大小,字体颜色等等.可以在res/value ...
- apk开发用什么语言!从入门到精通的Android进阶学习笔记整理,醍醐灌顶!
行业激烈变化时,恰恰是机会最多的时候 坦白讲,许多人骨子里害怕变化和竞争. 其实大可不必. 一来,怕也没用嘛.二来,变化越快,组合要素增加了,意味着新的工作机会越多. 就像传统媒体VS新媒体. 放在1 ...
- android 自定义 theme,为Android手机制作自定义主题
我是一名新的移动开发人员,我知道如何在应用程序上放置主题,到目前为止,我已经能够制作2个移动应用程序,但我想尝试为手机制作自定义主题.我想知道是否有人对以下内容有想法. 1.how to make a ...
最新文章
- 我国的人工智能芯片的市场规模及发展前景
- poj2441 Arrange the Bulls
- python-pygame激动时刻你我共享
- BigDecimal四舍五入与保留位
- 推荐10个技术圈优质的公众号大号
- linux kvm百度云,容器与云|如何在 Ubuntu Linux 上使用 KVM 云镜像
- (CF#257)B. Jzzhu and Sequences
- @babel/polyfill按需加载
- K3CLOUD表关联
- (转)金融从业者将被人工智能取代?
- 什么是「重置SMC、NVRAM、PRAM」?看完这篇文章你就懂了!
- 1094: 【基础】填词 【循环】
- ES选举:Elasticsearch中Master选举完全解读
- MOS管的导通过程及损耗分析
- 【论文笔记】MultiPath: Multiple Probabilistic Anchor TrajectoryHypotheses for Behavior Prediction
- 如何获取当前地址以及天气温度情况,适用于微信小程序(端午假期将至,祝愿大家端午快乐)
- 华为2012实验室无线通信领域的首席专家朱佩英博士
- 计算机毕业设计 SpringBoot+Vue线上素菜超市平台蔬菜商城管理系统 蔬菜超市平台系统
- ubuntu 系统的快捷键
- iOS6系统如何升级 菜鸟也能轻松上手
热门文章
- 篮球比赛24秒能不能用计算机控制,请问篮球24秒倒计时牌哪家是全金属面板的?...
- 我的Qt作品(5)使用Qt+Halcon实现模板匹配;支持ROI框选/橡皮擦涂抹功能
- 我的2016 “CSDN博客之星” 韩俊强的博客
- Power BI笔记:给排名度量添加矢量图标效果
- MSTP详解- 原理篇
- python 仪表盘数据显示_Python制作仪表盘图,比Excel快速百倍
- ProFOLD:普通笔记本3小时跑完的蛋白质结构「从头预测」,努力赶超AlphaFold2
- matlab中找矩阵最小值,matlab寻找矩阵最小值
- LaTeX \genfrac 分式命令
- LCD液晶显示器 ----------- 原理篇