Я новичок в этом, и любая помощь приветствуется! - =)
У меня есть цвета в списке массивов, которые выбираются в действии settings с использованием флажков. Я хочу, чтобы они отображались в фоновом режиме sequence в al oop.
. Цвета из значений "colors. xml". В настоящее время приложение продолжает сбой при переходе от действия настройки к действию sequence .
Настройки Activity:
package com.example.lightbox;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;
import java.util.ArrayList;
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Button sequence_go = findViewById(R.id.sequence_go);
CheckBox yellow = findViewById(R.id.yellow_check);
CheckBox orange = findViewById(R.id.orange_check);
CheckBox red = findViewById(R.id.red_check);
CheckBox pink = findViewById(R.id.pink_check);
CheckBox purple = findViewById(R.id.purple_check);
CheckBox blue = findViewById(R.id.blue_check);
CheckBox aqua = findViewById(R.id.aqua_check);
CheckBox lime = findViewById(R.id.lime_check);
CheckBox green = findViewById(R.id.green_check);
CheckBox white = findViewById(R.id.white_check);
final ArrayList<Integer> colorList = new ArrayList<>();
white.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
colorList.add(R.color.white);
Toast.makeText(SettingsActivity.this, "white Checked", Toast.LENGTH_SHORT).show();
}
});
yellow.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
colorList.add(R.color.yellow);
Toast.makeText(SettingsActivity.this, "yellow Checked", Toast.LENGTH_SHORT).show();
}
});
orange.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
colorList.add(R.color.orange);
Toast.makeText(SettingsActivity.this, "orange Checked", Toast.LENGTH_SHORT).show();
}
});
red.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
colorList.add(R.color.red);
Toast.makeText(SettingsActivity.this, "red Checked", Toast.LENGTH_SHORT).show();
}
});
pink.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
colorList.add(R.color.pink);
Toast.makeText(SettingsActivity.this, "pink Checked", Toast.LENGTH_SHORT).show();
}
});
purple.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
colorList.add(R.color.purple);
Toast.makeText(SettingsActivity.this, "purple Checked", Toast.LENGTH_SHORT).show();
}
});
blue.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
colorList.add(R.color.blue);
Toast.makeText(SettingsActivity.this, "blue Checked", Toast.LENGTH_SHORT).show();
}
});
aqua.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
colorList.add(R.color.aqua);
Toast.makeText(SettingsActivity.this, "aqua Checked", Toast.LENGTH_SHORT).show();
}
});
lime.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
colorList.add(R.color.lime);
Toast.makeText(SettingsActivity.this, "lime Checked", Toast.LENGTH_SHORT).show();
}
});
green.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
colorList.add(R.color.green);
Toast.makeText(SettingsActivity.this, "green Checked", Toast.LENGTH_SHORT).show();
}
});
sequence_go.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Sequence_Activity.class);
intent.putExtra("seqColors", colorList);
Toast.makeText(SettingsActivity.this, "To Sequence_Activity", Toast.LENGTH_SHORT).show();
startActivity(intent);
}
});
}
}
Последовательность действий:
package com.example.lightbox;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class Sequence_Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sequence);
ConstraintLayout sequence = findViewById(R.id.sequence_screen);
Bundle bundle = getIntent().getExtras();
int bgColor = bundle.getInt("seqColors", -1);
ValueAnimator anim = ValueAnimator.ofFloat(0, 1); // animate from 0 to 1
anim.setDuration(300); // for 300 ms
sequence.setBackgroundColor(getResources().getColor(bgColor));
sequence.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), SettingsActivity.class);
Toast.makeText(Sequence_Activity.this,"Settings Clicked",Toast.LENGTH_SHORT).show();
startActivity(intent);
}
});
}
}
Цвета. xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<color name="charcoal">#262626</color>
<color name="yellow">#FFFF00</color>
<color name="orange">#FF8400</color>
<color name="red">#FF0000</color>
<color name="green">#009900</color>
<color name="lime">#00FF00</color>
<color name="aqua">#00EEFF</color>
<color name="blue">#0000ff</color>
<color name="purple">#8c1aff</color>
<color name="pink">#ff66ff</color>
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
<color name="grey25">#bfbfbf</color>
<color name="grey50">#808080</color>
<color name="grey75">#404040</color>
<color name="grey80">#333333</color>
<color name="grey85">#262626</color>
<color name="grey90">#1a1a1a</color>
<color name="grey95">#0d0d0d</color>
</resources>
Logcat:
**--------- beginning of crash**
2020-03-06 09: 18: 30.662 15050-15050 / com.example.lightbox E / AndroidRuntime: ИСКЛЮЧИТЕЛЬНОЕ ИСКЛЮЧЕНИЕ: основной процесс: com.example.lightbox, PID: 15050 java .lang .RuntimeException: Невозможно начать действие. (ActivityThread. java: 3270) в android .app.ActivityThread.handleLaunchActivity (ActivityThread. java: 3409) в android .app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem. java: 83) в android .app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor. java : 135) в android .app.servertransaction.TransactionExecutor.execute (TransactionExecutor. java: 95) в android .app.ActivityThread $ H.handleMessage (ActivityThread. java: 2016) в android. os.Handler.dispatchMessage (Обработчик. java: 107) в android .os.Looper.l oop (Looper. java: 214) в android .app.ActivityThread.main (ActivityThread. java: 7356) в java .lang.reflect.Method.invoke (собственный метод) в com. android .internal.os.RuntimeInit $ MethodAndArgsCaller.run (RuntimeInit. java: 492) в com. android .internal.os.ZygoteInit.main (ZygoteInit. java: 930) Причина: android .content.res.Resources $ NotFoundException: идентификатор ресурса # 0xffffffff в android .content.res.ResourcesImpl.getValue (ResourcesImpl. java: 237) в android .content.res.Resources.getColor (Resources. java: 982) в android .content.res.Resources.getColor (Resources. java: 958 ) в com.example.lightbox.Sequence_Activity.onCreate (Sequence_Activity. java: 25) в android .app.Activity.performCreate (Activity. java: 7802) в android .app.Activity.performCreate ( Activ ity. java: 7791) в android .app.Instrumentation.callActivityOnCreate (Instrumentation. java: 1299) в android .app.ActivityThread.performLaunchActivity (ActivityThread. java: 3245) в android .app.ActivityThread.handleLaunchActivity (ActivityThread. java: 3409) в android .app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem. java: 83) в android .app.servertransaction.TransactionExecutor.executeCallbacks ( . java: 135) в android .app.servertransaction.TransactionExecutor.execute (TransactionExecutor. java: 95) в android .app.ActivityThread $ H.handleMessage (ActivityThread. java: 2016) в android .os.Handler.dispatchMessage (Обработчик. java: 107) в android .os.Looper.l oop (Looper. java: 214) в android .app.ActivityThread.main (ActivityThread. java: 7356) в java .lang.reflect.Method.invoke (собственный метод) в com. android .internal.os.RuntimeInit $ MethodAndArgsCaller.run (RuntimeInit. java: 492) по тел. android .internal.os.ZygoteInit.main (ZygoteInit. java: 930)