PopupWindow设置动画
布局文件
在res创建一个anim在里面创建两个布局文件分别写上如下图
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
>
<translate android:fromXDelta="-300" android:toXDelta="0"></translate>
<alpha android:fromAlpha="0.1" android:toAlpha="1"></alpha>
</set>
下边是淡出上边是淡入
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
>
<translate android:fromXDelta="0" android:toXDelta="300"></translate>
<alpha android:fromAlpha="1" android:toAlpha="0.1"></alpha>
</set>
在values中创建一个style文件将他们引入进来
<style name="pop_Window" parent="android:Animation">
<item name="android:windowEnterAnimation">@anim/popup_anim</item>
<item name="android:windowExitAnimation">@anim/popup_out</item>
</style>
最后就是我们的主要代码
将我们之前就写好的布局和id都初始化数据之后创建一个PopupWindow加载我们需要的布局必不可少的布局三要素宽高应用布局然后设置窗口透明度然后选择设置样式然后取消窗口透明度最后动画效果和设置点击外部取消然后设置弹出位置
add = (ImageView) findViewById(R.id.add);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupWindow popupWindow = new PopupWindow(app2.this);
View inflate = LayoutInflater.from(app2.this).inflate(R.layout.waibu_layout, null);
popupWindow.setContentView(inflate);
popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setWidth(600);
WindowManager.LayoutParams attributes = getWindow().getAttributes();
attributes.alpha = 0.5f;
getWindow().setAttributes(attributes);
popupWindow.setAnimationStyle(R.style.pop_Window);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
WindowManager.LayoutParams attributes1 = getWindow().getAttributes();
attributes1.alpha = 1f;
getWindow().setAttributes(attributes1);
}
});
popupWindow.setAnimationStyle(R.style.pop_Window);
popupWindow.setOutsideTouchable(true);
popupWindow.showAsDropDown(add,100,100);
}
});
Notification通知最简单的(无交互)
设置一个布局弄一个按钮即可
text1 = (Button) findViewById(R.id.text1);
text1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Notification.Builder builder = new Notification.Builder(app3.this);
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentTitle("标题");
builder.setContentText("这就是发送的内容");
Notification build = builder.build();
NotificationManager systemService = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
systemService.notify(1, build);
}
});
双击退出
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK ){
if(System.currentTimeMillis() - exitTime > 2000){
Toast.makeText(this,"在点就退出",Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
return true;
}else{
finish();
}
}
return super.onKeyDown(keyCode, event);
}