作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
GrallocAllocator unsupport colortype 6
GrallocAllocator decode bitmap failed, reset to heapAllocator
这是我收到的消息。你能告诉我我做错了什么吗?
private static final String KEY_INDEX = "index";
private static final String KEY_INDEX2 = "index2";
private static final String KEY_INDEX3 = "index3";
private static final String KEY_INDEX4 = "index4";
private static final String KEY_INDEX5 = "index5";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.easy_quiz);
correctAnswerColor = getResources().getColor(R.color.correctAnswerButton);
incorrectAnswerColor = getResources().getColor(R.color.incorrectAnswerButton);
if(savedInstanceState != null) {
mCurrentIndex = savedInstanceState.getInt(KEY_INDEX, 0);
if(savedInstanceState.getBoolean(KEY_INDEX2, false)) {
mTrueButton.getBackground().setColorFilter(correctAnswerColor, PorterDuff.Mode.MULTIPLY);
}
if(savedInstanceState.getBoolean(KEY_INDEX3, false)) {
mTrueButton.getBackground().setColorFilter(incorrectAnswerColor, PorterDuff.Mode.MULTIPLY);
}
if(savedInstanceState.getBoolean(KEY_INDEX4, false)) {
mFalseButton.getBackground().setColorFilter(correctAnswerColor, PorterDuff.Mode.MULTIPLY);
}
if(savedInstanceState.getBoolean(KEY_INDEX5, false)) {
mFalseButton.getBackground().setColorFilter(incorrectAnswerColor, PorterDuff.Mode.MULTIPLY);
}
} (...)
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Log.i(TAG, "OnSaveInstanceState");
outState.putInt(KEY_INDEX, mCurrentIndex);
outState.putBoolean(KEY_INDEX2, mIsTrueButtonGreen);
outState.putBoolean(KEY_INDEX3, mIsTrueButtonRed);
outState.putBoolean(KEY_INDEX4, mIsFalseButtonGreen);
outState.putBoolean(KEY_INDEX5, mIsFalseButtonRed);
}
我读到,要设置颜色,最好使用 getBackground.setColorFilter。不幸的是,在这种情况下它似乎不起作用。我该怎么办是个问题。
最佳答案
您应该根据以下内容修改您的代码:
private int correctAnswerColor, incorrectAnswerColor;
private String PREFS_NAME = "test";
private boolean isColored = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
correctAnswerColor = getResources().getColor(R.color.correct);
//Sets color
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
findViewById(R.id.button).getBackground().setColorFilter(correctAnswerColor, PorterDuff.Mode.MULTIPLY);
isColored = true;
}
});
//Reads color
SharedPreferences sp = getSharedPreferences(PREFS_NAME,0 );
isColored = sp.getBoolean("isValid", isColored);
//Sets color of btt
if(isColored) {
findViewById(R.id.button).getBackground().setColorFilter(correctAnswerColor, PorterDuff.Mode.MULTIPLY);
}
}
@Override
protected void onStop() {
super.onStop();
//Defines SharedPreferences & Saves data
SharedPreferences sp = getSharedPreferences(PREFS_NAME,0 );
SharedPreferences.Editor ed = sp.edit();
ed.putBoolean("isValid", isColored);
//Commits edits
ed.commit();
}
关于java - 获取savedInstanceState时的"GrallocAllocator unsupport colortype 6",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44317511/
GrallocAllocator unsupport colortype 6 GrallocAllocator decode bitmap failed, reset to heapAllocato
我是一名优秀的程序员,十分优秀!