简体   繁体   中英

Disable animation for Switch widget

I need to use the Switch widget as a link or a button (this is for design reasons beyond me). If you click on the Switch then a WebView opens. There must be no animation or appearance change in the Switch.

This is my naive code:

public class MainActivity extends Activity {

    private WebView wv;

    private Switch s;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        s = new Switch(this);
        s.setClickable(true);
        linearLayout.addView(s);

        wv = new WebView(this);
        wv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
        wv.setWebViewClient(new WebViewClient());
        linearLayout.addView(wv);

        super.setContentView(linearLayout);
    }

    @Override
    protected void onResume() {
        super.onResume();

        s.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                wv.loadUrl("https://www.google.com");
            }
        });
    }
}

Do you know if I can disable the animation and appearance change in the Switch widget?

I found an okayish solution:

s = new Switch(this) {

    @Override
    public void setChecked(boolean checked) {
        super.setChecked(false);
    }
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM