android全屏模式动画,Android-->Toast全屏和动画(模拟QQ样式)

64db5aa824e4?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

这里写图片描述

如图, 底下是一个空布局, 参考我的博文: http://blog.csdn.net/angcyo/article/details/53967099

顶部就是一个Toast. 全屏,并且进入和退出都有自定义的动画.

正文:

系统并没有提供设置全屏和动画的方法.

但是Java有一个神器, 反射. 我们可以通过反射. 肆意修改成员变量.

//全屏和动画的设置方法

private static void initToast(Toast toast) {

try {

Field mTN = toast.getClass().getDeclaredField("mTN");

mTN.setAccessible(true);

Object mTNObj = mTN.get(toast);

Field mParams = mTNObj.getClass().getDeclaredField("mParams");

mParams.setAccessible(true);

WindowManager.LayoutParams params = (WindowManager.LayoutParams) mParams.get(mTNObj);

params.width = -1;//-1表示全屏, 你也可以设置任意宽度.

params.height = -2;// (int) dpToPx(context, T_HEIGHT);

params.windowAnimations = R.style.BaseToastAnimation;//设置动画, 需要是style类型

} catch (Exception e) {

e.printStackTrace();

}

}

有了以上方法, 你用该就可以直接使用了.

下面提供一下我的封装:

public static void show(Context context, CharSequence charSequence) {

View layout;

if (toast == null) {

toast = Toast.makeText(context, "", Toast.LENGTH_SHORT);

initToast(toast);

layout = LayoutInflater.from(context).inflate(R.layout.base_toast, null);//自定义的布局

((TextView) layout.findViewById(R.id.base_toast_text_view)).setText(charSequence);

toast.setView(layout);

toast.setGravity(Gravity.TOP, 0, 0);//从顶部开始显示

toast.getView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);//设置Toast可以布局到系统状态栏的下面

} else {

layout = toast.getView();

}

TextView titleView = find(layout, R.id.base_toast_text_view);

ImageView imageView = find(layout, R.id.base_toast_image_view);

titleView.setText(charSequence);//设置文本信息

toast.show();

}

是不是很简单?

布局阴影的方法:

在5.0以上的系统中可以通过下面的方法设置:

android:elevation="10dp"

万能的方法:

//阴影的渐变颜色

android:angle="-90"

android:centerColor="#000"

android:endColor="#00000000"

android:startColor="#000"

android:type="linear"

/>

//阴影的偏移高度

//布局的背景颜色

至此: 文章就结束了,如有疑问: QQ群:274306954 欢迎您的加入.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值