一个简单的购物车加减按钮,自定义控件实现,非常简单,有兴趣的可以自己尝试一下
import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import com.shizhibang.jdcom.R; public class NumberButton extends RelativeLayout implements View.OnClickListener { private ImageView jia; private ImageView jian; private TextView num; public NumberButton(Context context) { this(context,null); } public NumberButton(Context context, AttributeSet attrs) { this(context, attrs, 0); } public NumberButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context, attrs); } private void init(Context context, AttributeSet attrs) { View view = View.inflate(context, R.layout.num, null); addView(view); jia = view.findViewById(R.id.jia); jian = view.fi