Android shap selector animation 与 Toast退出问题


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

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



    
    
    android:radius="9dp"
        android:topLeftRadius="2dp"
        android:topRightRadius="2dp"
        android:bottomLeftRadius="2dp"
        android:bottomRightRadius="2dp"/>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


selector:图片,文字点击效果

图片:state          drawable



    
    
    

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



    color="#000000" android:state_selected="true"/>
    


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:[email protected]
 * @版本: 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();
	}



你可能感兴趣的:(Android)