继承LinearLayout的自定义view

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);
            }
        }
    }




}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值