您的位置:首页 > 移动开发 > Android开发

Android shap selector animation 与 Toast退出问题

2015-09-11 15:52 417 查看


Shap:使用场景 解决圆角问题

shape用于设定形状,可以在selector,layout等里面使用,有6个子标签,各属性如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<!-- 圆角 -->
<corners
<span style="color:#ff6666;">android:radius="9dp"</span>
android:topLeftRadius="2dp"
android:topRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:bottomRightRadius="2dp"/><!-- 设置圆角半径 -->

<!-- 渐变 -->
<gradient
android:startColor="@android:color/white"
android:centerColor="@android:color/black"
android:endColor="@android:color/black"
android:useLevel="true"
android:angle="45"
android:type="radial"
android:centerX="0"
android:centerY="0"
android:gradientRadius="90"/>

<!-- 间隔 -->
<padding
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/><!-- 各方向的间隔 -->

<!-- 大小 -->
<size
android:width="50dp"
android:height="50dp"/><!-- 宽度和高度 -->

<!-- 填充 -->
<solid
android:color="@android:color/white"/><!-- 填充的颜色 -->

<!-- 描边 -->
<stroke
android:width="2dp"
android:color="@android:color/black"
android:dashWidth="1dp"
android:dashGap="2dp"/>

</shape></span>


selector:图片,文字点击效果

图片:state          drawable

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/" android:state_selected="true"/>
<item android:drawable="@drawable/" android:state_pressed="true"/>
<item android:drawable="@drawable/" android:state_pressed="false"/>
</selector>

android:state_pressed 

如果是true,当被点击时显示该图片,如果是false没被按下时显示默认。

android:state_focused 

如果是true,获得焦点时显示;如果是false没获得焦点显示默认。

android:state_selected

如果是true,当被选择时显示该图片;是false未被选择时显示该图片。

android:state_checkable

 如果值为true,当CheckBox能使用时显示该图片;false,当CheckBox不能使用时显示该图片。

android:state_checked

如果值为true,当CheckBox选中时显示该图片;false,当CheckBox为选中时显示该图片。

android:state_enabled

如果值为true,当该组件能使用时显示该图片;false,当该组件不能使用时显示该图片。

 

android:state_window_focused

如果值为true,当此activity获得焦点在最前面时显示该图片;false,当没在最前面时显示该图片。

文字:state color

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:<span style="color:#ff0000;">color</span>="#000000" android:<span style="color:#ff0000;">state</span>_selected="true"/>
<item android:color="@color/black" android:state_pressed="false"/>
</selector>


animation: 动画效果

1.帧动画

2.补间动画

旋转rotate 平移translate 渐变alpha 大小scale

3.属性动画

Toast:防止程序退出,还在弹

其实很简单,Toast有个cancel 方法
onDestroy()调用一下就ok了。

声明Toast对象

private Toast mToast = new Toast(this); //在OnCreate中
private  LayoutInflater inflater = LayoutInflater.from(this);
private View viewToast = inflater.inflate(R.layout.mtoast, null);//自定义Toast布局
mToast.setView(view);//加载
mToast.setDuration(1000);//设置显示时间

mToast.cancel();//onDestroy中
package com.ly.myfrawork.widget;

import android.content.Context;
import android.view.View;
import android.widget.Toast;

/************************************************
* @版权: Copyright (c) 1998-2014 *********公司技术开发部
* @创建人版本: 刘洋 E-mail:465282857@qq.com
* @版本: 1.0
* @创建日期: 2015-8-7 上午10:09:22
* @类描述:
*
* @修改记录:
* @版本:
************************************************/
@Deprecated
public class MyToast
{
private Toast mToast;

public MyToast(Context context)
{
mToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
}

public void show(String context)
{
mToast.setText(context);
mToast.show();
}

public void cancel()
{
mToast.cancel();
}

public void setView(View view)
{
mToast.setView(view);
}
}


推荐application中统一Toast

static Toast tosToast;

public static void makeText(String msg)
{
if (tosToast != null)
tosToast.cancel();
tosToast = Toast.makeText(mContext, msg, Toast.LENGTH_LONG);
tosToast.show();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息