Android 动态添加Button

2022-08-12  本文已影响0人  rv要努力
 Button btn = new Button(mContext);
 btn.setText("调用JS");
 btn.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {
               CallJS();
       }
 });
 Button btn1 = new Button(mContext);
 btn1 .setText("刷新页面");
 btn1 .setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
         //调用刷新     
         webView.reload();
    }
 });

 LinearLayout llt  = new LinearLayout(this);
 llt.setOrientation(LinearLayout.HORIZONTAL);
 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
 llt.setLayoutParams(params);
 llt.addView(btn);
 llt.addView(btn1 );
上一篇下一篇

猜你喜欢

热点阅读