1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| package com.pack.customcomponent;
import com.pack.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.TextView;
public class Custombutton extends FrameLayout{
private String label;
private Drawable image;
private TextView mText;
private ImageButton mImageButton;
public Custombutton(Context context) {
super(context);
}
public Custombutton(Context context, AttributeSet attrs) {
super(context, attrs);
initStyleButton(attrs);
}
private void initStyleButton(AttributeSet attrs){
TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.Custombutton);
String label = a.getString(R.styleable.Custombutton_label);
Drawable image = a.getDrawable(R.styleable.Custombutton_image);
setLabel(label);
setImage(image);
a.recycle();
}
public String getLabel() {
return label;
}
public void setLabel(String unLabel) {
this.label = unLabel;
}
public Drawable getImage() {
return image;
}
public void setImage(Drawable uneImage) {
this.image = uneImage;
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
}
} |
Partager