Ответ 1
Если вы довольны setColorFilter(0xFF000000, Mode.MULTIPLY)
, то как создать пользовательский компонент, который расширяет ImageButton?
Что-то вроде:
(Извините, у меня не было возможности проверить это)
package com.example;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageButton;
public class IosImageButton extends ImageButton implements OnTouchListener
{
public IosImageButton(final Context context, final AttributeSet attrs, final int defStyle)
{
super(context, attrs, defStyle);
this.init();
}
public IosImageButton(final Context context, final AttributeSet attrs)
{
super(context, attrs);
this.init();
}
public IosImageButton(final Context context)
{
super(context);
this.init();
}
private void init()
{
super.setOnTouchListener(this);
}
@Override
public boolean onTouch(final View view, final MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
// touchDown event -> Change color overlay. goes here
// e.g. this.setColorFilter(0xFF000000, Mode.MULTIPLY);
return true;
case MotionEvent.ACTION_UP:
// touchUp event -> remove color overlay, and perform button action.
// e.g. this.setColorFilter(0xFF000000, Mode.MULTIPLY);
return true;
default:
return false;
}
}
}
Затем view.xml
<RelativeLayout 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"
tools:context=".MainActivity" >
<com.example.IosImageButton
<!-- add standard ImageButton setting here -->
/>
</RelativeLayout>