[英]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.
如果单击“开关”,则将打开一个WebView。 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);
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.