PushButton.java
package *****Paketnamen*****;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Button;
/***Effekt-Taste zum Drücken***/
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 *****Paketnamen*****;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Button;
/***Halbtransparenter Effektknopf***/
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">
<!---Taste, die beim Drücken schrumpft-->
<*****Paketnamen*****.PushButton
android:id="@+id/button_sample01"
android:layout_width="200dp"
android:layout_height="60dp"
android:background="@drawable/button_sample"
/>
<!---Halbtransparente Taste beim Drücken-->
<*****Paketnamen*****.AlphaButton
android:id="@+id/button_sample02"
android:layout_width="200dp"
android:layout_height="60dp"
android:background="@drawable/button_sample"
/>
</LinearLayout>
das ist alles
Recommended Posts