【问题标题】:Toggle button to enable/disable images in webview切换按钮以启用/禁用 web 视图中的图像
【发布时间】:2014-08-08 02:25:31
【问题描述】:

如何使用切换按钮启用或禁用在 web 视图中加载图像?我已经使用了这个代码,但图像是永久启用的。

   toggle=(ToggleButton)findViewById(R.id.tglbtn1);
        toggle.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {
               // TODO Auto-generated method stub
              if(toggle.isChecked())
              {
               Toast.makeText(getApplicationContext(), "The state is changed to on", Toast.LENGTH_LONG).show();
               webView.getSettings().setLoadsImagesAutomatically(true);// Enable Image
                // Loading


              }
                else
                {
                  Toast.makeText(getApplicationContext(), "The state is changed to off", Toast.LENGTH_LONG).show();
                  webView.getSettings().setLoadsImagesAutomatically(false);// Enable Image
                    // Loading

                }
                 }
                 });

【问题讨论】:

    标签: android button toggle


    【解决方案1】:

    在android中实现切换按钮的更好方法,

    布局xml,

    <ToggleButton
                    android:id="@+id/leave_toggle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/custom_toggle"
                    android:minHeight="1dp"
                    android:minWidth="1dp"
                    android:textOff=""
                    android:textOn="" />
    

    可绘制的 xml, @drawable/custom_toggle

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:drawable="@drawable/notification_on" android:state_checked="true"/>
        <item android:drawable="@drawable/notification_off" android:state_checked="false"/>
    
    </selector>
    

    notification_on 和 notification_off 是图片

    内部活动,

    private ToggleButton getToggleButton(int id) {
            return (ToggleButton) findViewById(id);
        }
    

    将 oncheckedchagelistener 设置为切换按钮,当用户使用 ischecked 启用或禁用按钮时会通知

     getToggleButton(R.id.leave_toggle).setOnCheckedChangeListener(
                        new OnCheckedChangeListener() {
                            @Override
                            public void onCheckedChanged(CompoundButton toggleButton,
                                    boolean isChecked) {
                                if(isChecked)
                               {
                                // enabled
                                 }else
                                      {
                               //disabled
                                      }
                            }
                        });
    

    【讨论】:

    • 不知道如何实现,您能帮忙吗?还是编辑代码?
    猜你喜欢
    • 2015-04-16
    • 2014-01-04
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    • 2013-06-20
    • 2020-04-19
    • 1970-01-01
    相关资源
    最近更新 更多