gpt4 book ai didi

java - 获取savedInstanceState时的"GrallocAllocator unsupport colortype 6"

转载 作者:行者123 更新时间:2023-12-02 13:00:36 24 4
gpt4 key购买 nike

 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com