ImageButton------------------------------------------------> 一.Java  代码: 在drawable目录下添加新的xml文件 button_add_x.xmlimageButton.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { if(event.getAction() ==…
我们在界面上经常会用到button按钮,但通常button点击后看不到点击的效果,如果用户连续点击了两次,就会报NAR错误,这样交互性就比较差了.如果我们自定义了button点击效果,比如我们点击了button能让我们看到我们确实点击了button按钮,这样就会有效的避免重复点击了. 自定义点击效果有两种方式,一种是在xml中定义,另一种是在代码中定义. 首先看一下如何在xml中定义: 在drawable下新建selector.xml文件: <?xml version="1.0"…
public class PostTextView extends TextView { private Handler handler = new Handler(Looper.getMainLooper()); public PostTextView(Context context) { super(context); } public PostTextView(Context context, AttributeSet attrs) { super(context, attrs); } p…
public class BaseActivity extends Activity { protected boolean isDestroy; //防止反复点击设置的标志.涉及到点击打开其它Activity时.将该标志设置为false.在onResume事件中设置为true private boolean clickable=true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(…
实现点击图片(ImageView)变暗效果,有一个较简单的方法,就是讲目标图片设置为背景图片(setBackground),再创建一个selector.xml文件,里面放置一张普通状态时的透明图片,一张点击状态下的棕色半透明图片,将其设置为ImageView的源图片.这样在点击ImageView时,源图片会变换透明度,达到变暗效果.但这种方法有个缺点:由于源图片已经被限制死了,假如我们需要自定义背景图片,将目标图片放置在背景图片上,就无法实现了.这里介绍一种通过滤镜和监听onTouchEvent…
<Button android:id="@+id/btnTest" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button" /> <TextView android:id="@+id/myTestText" android:layout_width=&quo…
selector 1.selector 从单词的意思来说:选择者,选择器,就是对你的目标的控制. 从API来说: A controller for the selection of SelectableChannel objects. Selectable channels can be registered with a selector and get a SelectionKey that represents the registration. The keys are also add…
今天做项目时,ListView中含有了Button组件,心里一早就知道肯定会有冲突,因为以前就遇到过,并解决过,可惜当时没有记录下来. 今天在做的时候,继续被这个问题郁闷了一把,后来解决后,赶紧来记录下,以便日后参考. 首先,其实Listview中Button按钮点击事件冲突这种问题压根就不是太大的问题,因为我们完全可以将一个TextView的Backgroud设置成一个selector,也可以将一个TextView设计成一个按钮的样子,这样就可以绕过ListView和Button的冲突问题!…
1在代码中添加文字阴影 TextView 有一个方法 /**      * Gives the text a shadow of the specified radius and color, the specified      * distance from its normal position.      *      * @attr ref android.R.styleable#TextView_shadowColor      * @attr ref android.R.style…
布局文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orien…