PushButton.java
package *****package name*****;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Button;
/***Effect button to push***/
public class PushButton extends Button {
public PushButton(Context context) {
super(context);
}
public PushButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setPressed(boolean pressed) {
if(pressed){
this.setScaleY(0.92f);
this.setScaleX(0.96f);
}else{
this.setScaleY(1.0f);
this.setScaleX(1.0f);
}
super.setPressed(pressed);
}
}
AlphaButton.java
package *****package name*****;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Button;
/***Semi-transparent effect button***/
public class AlphaButton extends Button {
public AlphaButton(Context context) {
super(context);
}
public AlphaButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setPressed(boolean pressed) {
if(pressed){
this.setAlpha(0.75f);
}else{
this.setAlpha(1.0f);
}
super.setPressed(pressed);
}
}
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainframe"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000">
<!---Button that shrinks when pressed-->
<*****package name*****.PushButton
android:id="@+id/button_sample01"
android:layout_width="200dp"
android:layout_height="60dp"
android:background="@drawable/button_sample"
/>
<!---Semi-transparent button when pressed-->
<*****package name*****.AlphaButton
android:id="@+id/button_sample02"
android:layout_width="200dp"
android:layout_height="60dp"
android:background="@drawable/button_sample"
/>
</LinearLayout>
that's all
Recommended Posts