Soheil Afshari
Soheil Afshari

Reputation: 35

You need to use a Theme.AppCompat theme (or descendant) with this activity

I am trying to create an activity with a button that runs color picker for my app, here is my Activity code :

public class color extends AppCompatActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_color);
        final ImageView imgbck= (ImageView) findViewById(R.id.imageView4);
        ImageButton imgbt= (ImageButton) findViewById(R.id.colorpickerbt);
        imgbt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ColorPickerDialogBuilder
    .with(getApplicationContext())
    .setTitle("Choose color")
    .wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
    .density(12)
    .setOnColorSelectedListener(new OnColorSelectedListener() {
        @Override
        public void onColorSelected(int selectedColor) {
            String ss=Integer.toHexString(selectedColor);
            Toast.makeText(getApplicationContext(),ss,Toast.LENGTH_SHORT).show();
        }
    })
    .setPositiveButton("ok", new ColorPickerClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
            imgbck.setBackgroundColor(selectedColor);
        }
    })
    .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    })
    .build()
    .show();
            }
        });

    }

everything is working fine but when i hit the button i get this error :

FATAL EXCEPTION: main
Process: com.soheil.prolightfa, PID: 31576
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:310)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:279)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:253)
at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:76)
at android.support.v7.app.AlertController.installContent(AlertController.java:213)

im also adding my styles:

<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

and Style v14

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- API 14 theme customizations can go here. -->
    </style>

and v11

  <style name="AppBaseTheme" parent="Theme.AppCompat">
        <!-- API 11 theme customizations can go here. -->
    </style>

and i also changed the activity to Appcompactactivity what should i do ?

Upvotes: 0

Views: 4376

Answers (2)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

Your logcat throwing

 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
  • At First extends AppCompatActivity instead of Activity

public class color extends AppCompatActivity {

You can share your Application style.

  1. First section parent="@android:style/Theme.Holo.Light">

  2. another section parent="android:Theme.Holo.Light"> in v11

You need to use a Theme.AppCompat theme (or descendant) with this activity

Upvotes: 1

mubeen
mubeen

Reputation: 839

Go to your styles and put the parent

parent="@android:style/Theme.Holo.Light"

instead of

parent="Theme.AppCompat"

Or you can use AppCompat for backward compatibility.

Upvotes: 1

Related Questions