package wld.bawei.com.myonemoni2.view; import android.content.Context; import android.content.Intent; import android.content.res.TypedArray; import android.graphics.Color; import android.net.wifi.aware.PublishConfig; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; import wld.bawei.com.myonemoni2.Main2Activity; import wld.bawei.com.myonemoni2.MainActivity; import wld.bawei.com.myonemoni2.R; /** * Created by 大金鑫 on 2017/12/2. */ public class Headerclass extends LinearLayout implements View.OnClickListener { private String color; public Headerclass(Context context) { this(context,null); } public Headerclass(Context context, @Nullable AttributeSet attrs) { this(context, attrs,0); } public Headerclass(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.Headerclass, defStyleAttr, 0); color = ta.getString(R.styleable.Headerclass_c); if(color==null){ color="#ff00ff"; } init(); } private void init() { View view = View.inflate(getContext(), R.layout.header, this); LinearLayout lin = view.findViewById(R.id.lin); TextView t1 = view.findViewById(R.id.t1); TextView t2 = view.findViewById(R.id.t2); TextView t3 = view.findViewById(R.id.t3); t3.setOnClickListener(this); t1.setOnClickListener(this); lin.setBackgroundColor(Color.parseColor(color)); } @Override public void onClick(View view) { switch (view.getId()){ case R.id.t1:{ }break; case R.id.t3:{ Intent intent = new Intent(getContext(), Main2Activity.class); getContext().startActivity(intent); } } } }
继承LinearLayout的自定义view
最新推荐文章于 2024-06-29 22:58:51 发布