我正在尝试使用壁画图像查看器, 但是,当正在执行click侦听器时,我收到此错误
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:355)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:324)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:285)
at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:83)
at android.support.v7.app.AlertController.installContent(AlertController.java:225)
at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:257)
at android.app.Dialog.dispatchOnCreate(Dialog.java:397)
at android.app.Dialog.show(Dialog.java:298)
at com.stfalcon.frescoimageviewer.ImageViewer.show(ImageViewer.java:61)
at com.stfalcon.frescoimageviewer.ImageViewer$Builder.show(ImageViewer.java:435)
at com.unobridge.www.unobridgepartner.view.service_detail.adapters.QueryImageGalleryAdapter$1.onClick(QueryImageGalleryAdapter.java:67)
at android.view.View.performClick(View.java:5207)
at android.view.View$PerformClick.run(View.java:21177)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
和适配器中的代码,适配器具有活动的上下文,它再次传递给FrescoImageViewer:
holder.simpleDraweeView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, holder.getAdapterPosition()+" ");
new ImageViewer.Builder<>(context,fileMaps)
.setFormatter(new ImageViewer.Formatter<FileMap>(){
@Override
public String format(FileMap fileMap) {
return fileMap.getUrls().get(0).getUrl();
}
})
.show();
}
});
活动代码:
package com.unobridge.www.unobridgepartner.view.service_detail.activities;
import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MenuItem;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.unobridge.www.unobridgepartner.R;
import com.unobridge.www.unobridgepartner.databinding.ActivityQueryImageGalleryBinding;
import com.unobridge.www.unobridgepartner.model.FileMap;
import com.unobridge.www.unobridgepartner.model.Ticket;
import com.unobridge.www.unobridgepartner.view.service_detail.adapters.QueryImageGalleryAdapter;
import com.unobridge.www.unobridgepartner.viewmodel.service_detail.activities.QueryImageGalleryViewModel;
import java.util.List;
public class QueryImageGalleryActivity extends AppCompatActivity {
private static final String TICKET_DATA = "ticket_data";
private ActivityQueryImageGalleryBinding binding;
private QueryImageGalleryViewModel queryImageGalleryViewModel;
private QueryImageGalleryAdapter queryImageGalleryAdapter;
private List<FileMap> fileMaps;
public static Intent newIntent(Context context, Ticket ticket){
Intent intent = new Intent(context, QueryImageGalleryActivity.class);
intent.putExtra(TICKET_DATA, ticket);
return intent;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Ticket ticket = getIntent().getParcelableExtra(TICKET_DATA);
binding = DataBindingUtil.setContentView(this, R.layout.activity_query_image_gallery);
queryImageGalleryViewModel = new QueryImageGalleryViewModel(getApplicationContext(), ticket);
binding.setViewModel(queryImageGalleryViewModel);
queryImageGalleryAdapter = new QueryImageGalleryAdapter(getApplicationContext(), ticket.getQueryImages());
Fresco.initialize(this);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getApplicationContext(), 2);
binding.queryImageRecyclerView.setLayoutManager(layoutManager);
binding.queryImageRecyclerView.setItemAnimator(new DefaultItemAnimator());
binding.queryImageRecyclerView.setAdapter(queryImageGalleryAdapter);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Query Image Gallery");
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
super.onBackPressed();
}
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:2)
您需要使用AppCompatActivity主题设置为Activity的上下文,而您的应用程序似乎没有使用
将所有getApplicationContext()
替换为QueryImageGalleryActivity.this
(当前活动/背景)