我有以下问题:我为CheckedTextView创建了定制的安卓类
public class CustomCheckedTextView extends CheckedTextView {
public CustomCheckedTextView(Context context) {
super(context);
this.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick(View v) {
((CheckedTextView) v) .toggle();
if (isChecked()){
setBackgroundColor(Color.GREEN);
} else {
setBackgroundColor(Color.RED);
}
}
}) ;
}
}并在主活动中使用它,如下所示:
LinearLayout llayout = (LinearLayout) findViewById(R.id.linearLayout1);
final CustomCheckedTextView checkedTV = new CustomCheckedTextView(this);
llayout.addView(checkedTV)所以我可以点击CustomCheckedTextView,背景将是绿色的。但是当我旋转手机的时候,背景又变白了。为什么会发生这种情况?
发布于 2013-06-24 16:46:35
将此代码添加到AndroidManifest.xml文件中
android:configChanges="orientation"发布于 2013-12-28 00:57:39
请不要使用configChanges完成此操作。了解它发生的原因以及如何保存状态是非常重要的。请阅读documentation on this topic。
https://stackoverflow.com/questions/17271281
复制相似问题