Android半透明提示效果的实现
2016-07-13 17:21
387 查看
实现方法是利用一个全屏的dialog加载一个带有半透明背景layout
具体实现方法如下:
首先,设置要覆盖在最上方的dialog的view
然后,在values/styles.xml添加style for 半透明
继续添加style for 淡入淡出效果:
在anim文件夹下,添加文件fade_in.xml for 淡入
添加文件fade_out.xml for 淡出
最后,在要弹出对话框的地方添加如下代码
其中字体为华康娃娃体,下面是一些常用的字体:
http://pan.baidu.com/s/1pLGP8ZT
实现效果如下:
具体实现方法如下:
首先,设置要覆盖在最上方的dialog的view
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg_transparent" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/iv_tips" android:layout_centerHorizontal="true" android:text="长按某一项弹出\n编辑、删除选项按钮\n\n\n\n知道啦~\n点我退出提示 ^_^" android:textColor="@color/white" android:gravity="center_horizontal" android:textSize="27sp" /> <ImageView android:id="@+id/iv_tips" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_alignParentTop="true" android:layout_marginLeft="78dp" android:layout_marginTop="154dp" android:src="@drawable/longclick" /> </RelativeLayout>
然后,在values/styles.xml添加style for 半透明
<style name="Dialog_Fullscreen"> <item name="android:windowBackground">@android:color/transparent </item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowAnimationStyle">@style/Dialog_Anim </item> <item name="android:colorBackgroundCacheHint">@null</item> </style>
继续添加style for 淡入淡出效果:
<style name="Dialog_Anim"> <item name="android:windowEnterAnimation">@anim/fade_in</item> <item name="android:windowExitAnimation">@anim/fade_out</item> </style>
在anim文件夹下,添加文件fade_in.xml for 淡入
<?xml version="1.0" encoding="utf-8"?> <!-- 左下角扩大--> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="0.001" android:toXScale="1.0" android:fromYScale="0.001" android:toYScale="1.0" android:pivotX="0%" android:pivotY="100%" android:duration="300" />
添加文件fade_out.xml for 淡出
<?xml version="1.0" encoding="utf-8"?> <!-- 右下角缩小 --> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="1.0" android:toXScale="0.001" android:fromYScale="1.0" android:toYScale="0.001" android:pivotX="100%" android:pivotY="100%" android:duration="300" />
最后,在要弹出对话框的地方添加如下代码
//显示提示信息 private void showTips(){ final Dialog dialog = new Dialog(this, R.style.Dialog_Fullscreen); dialog.setContentView(R.layout.tips_for_long_click_layout); dialog.show(); TextView tv = (TextView)dialog.findViewById(R.id.textView1); String fontPath = "fonts/hkwwt.TTF"; Typeface tf = Typeface.createFromAsset(getAssets(), fontPath); tv.setTypeface(tf); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); }
其中字体为华康娃娃体,下面是一些常用的字体:
http://pan.baidu.com/s/1pLGP8ZT
实现效果如下:
相关文章推荐
- Android如何解决多次fork进程的问题
- Android三种播放视频的方式
- 运行Android studio报错com.google.android.gms:play-services-appindexing:8.1.0
- Android代码设置Shape,corners,Gradient
- 出场、入场动画大全,基于NineOldAndroids轻松实现动画效果
- android 介绍Retrofit的简单使用
- 在android中进行视频的分割
- android下的状态选择器
- 替代复杂的Actionbar
- debug(1) Android手机连接不上
- Android studio 上使用aidl总结
- Android插件化原理系列(一)启动未声明的Activity
- Android关于JNI开发(2)-----Android Studio工具开发
- android的Proguard混淆
- android中button点击两次才响应onclick方法
- 快速集成Android实现下拉刷新上拉加载更多
- Android 在 SDK 版本5.0,N(API23)阶段startActivity()出错
- [Android]自定义垂直滚动的广告区
- Android 定位系统(GPS)开发详解
- android之自定义View和ViewGroup(二)(此篇不讲述代码,只讲述原理和结构,带你走进自定义的世界)