Android实现个人中心设置界面

在这里插入图片描述
xml:

 <com.example.rxhttpdemo.util.navbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/shoucang"
        app:icon="@mipmap/ic_launcher_round"
        app:hint="收藏"/>

value attrs xml:

 <declare-styleable  name="nav">
        <!--图片-->
        <attr name="icon" format="reference"/>
        <!--字体-->
        <attr name="hint" format="string"/>
        <!--是否密文-->
        <attr name="pass" format="boolean"/>
        <attr name="right_icon" format="reference"/>
    </declare-styleable>

正题代码:

public class navbar extends LinearLayout {
        private Context con;
        private int inputview_input_icon;
        private String inputview_input_hint;
        private boolean inputview_is_pass;

        private int right_icon;
        private View inflate;
        ImageView imageView;
        TextView editText;
        private View tv_search;

        public navbar(@NonNull Context context) {
            super(context);
            init(context, null);
            this.con=context;
        }

        public navbar(@NonNull Context context, @Nullable AttributeSet attrs) {
            super(context, attrs);
            init(context, attrs);
        }

        public navbar(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
            init(context, attrs);
        }


        private void init(Context context, AttributeSet attrs) {
            if(attrs==null){
                return;
            }

            TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.nav);
            inputview_input_icon = typedArray.getResourceId(R.styleable.nav_icon, R.mipmap.ic_launcher);
            right_icon = typedArray.getResourceId(R.styleable.nav_right_icon, R.mipmap.ic_launcher);
            inputview_input_hint = typedArray.getString(R.styleable.nav_hint);
            typedArray.recycle();

            inflate = LayoutInflater.from(context).inflate(R.layout.nav_bar, this, false);
            //imageView=  (ImageView)inflate.findViewById(R.id.tou);
            editText=  (TextView)inflate.findViewById(R.id.title);
            imageView=  (ImageView)inflate.findViewById(R.id.back);
            imageView.setImageResource(inputview_input_icon);
            editText.setText(inputview_input_hint);
            //editText.setInputType(inputview_is_pass?);
            addView(inflate);

        }


    }

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值