Android Cordova Snackbar Crash问题

时间:2018-05-29 09:14:32

标签: cordova android-snackbar

我在我的cordova自定义插件中使用Snackbar,我无法在插件中显示Snackbar,它不断发生崩溃

private FrameLayout mFrameLayout;
private Snackbar mSnackbar;

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    mFrameLayout = (FrameLayout) webView.getView().getParent();
}

@Override
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException {
    Log.v(TAG, "onRequestPermissionResult : " + requestCode);
    switch (requestCode) {
        case REQUEST_CODE: {
            if (ContextCompat.checkSelfPermission(cordova.getActivity(),
                    Manifest.permission.ACCESS_COARSE_LOCATION)
                    == PackageManager.PERMISSION_GRANTED) {
                Log.v(TAG, "PERMISSION_GRANTED : requestLocationUpdates");
                startLocationUpdates();
            } else {
                Log.v(TAG, PERMISSION_DENIED);
                Toast.makeText(cordova.getActivity(), PERMISSION_DENIED, Toast.LENGTH_LONG).show();
                showSnackbar(R.string.permission_denied_explanation,
                        R.string.settings, new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                PermissionHelper.requestPermission(GeoLocation.this,
                                        REQUEST_CODE, Manifest.permission.ACCESS_COARSE_LOCATION);
                                /*Intent intent = new Intent();
                                intent.setAction(
                                        Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                                Uri uri = Uri.fromParts("package",
                                        BuildConfig.APPLICATION_ID, null);
                                intent.setData(uri);
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                cordova.getActivity().startActivity(intent);*/
                            }
                        });

            }
            return;
        }

    }
}

private void showSnackbar(final int mainTextStringId, final int actionStringId,
                          View.OnClickListener listener) {

    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mSnackbar = Snackbar
                    .make(mFrameLayout, "Test", Snackbar.LENGTH_INDEFINITE);
            mSnackbar.show();
        }
    });
}

但是我的误差低于

Process: com.svb.mobilebanking, PID: 29280
java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=0, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.svb.mobilebanking/com.svb.mobilebanking.MainActivity}: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class <unknown>
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4491)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4534)
    at android.app.ActivityThread.-wrap20(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1752)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6940)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 Caused by: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class <unknown>
 Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class <unknown>
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
    at android.view.LayoutInflater.createView(LayoutInflater.java:647)
    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.support.design.widget.Snackbar.make(Snackbar.java:143)
    at com.svb.mobilebanking.GeoLocation$8.run(GeoLocation.java:304)
    at android.app.Activity.runOnUiThread(Activity.java:6272)
    at com.svb.mobilebanking.GeoLocation.showSnackbar(GeoLocation.java:300)
    at com.svb.mobilebanking.GeoLocation.access$000(GeoLocation.java:53)
    at com.svb.mobilebanking.GeoLocation$1.run(GeoLocation.java:126)
    at android.app.Activity.runOnUiThread(Activity.java:6272)
    at com.svb.mobilebanking.GeoLocation.onRequestPermissionResult(GeoLocation.java:123)
    at org.apache.cordova.CordovaInterfaceImpl.onRequestPermissionResult(CordovaInterfaceImpl.java:221)
    at org.apache.cordova.CordovaActivity.onRequestPermissionsResult(CordovaActivity.java:509)
    at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7728)
    at android.app.Activity.dispatchActivityResult(Activity.java:7551)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4487)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4534)
    at android.app.ActivityThread.-wrap20(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1752)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6940)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
    at android.content.res.TypedArray.getColorStateList(TypedArray.java:538)
    at android.widget.TextView.<init>(TextView.java:1239)
    at android.widget.TextView.<init>(TextView.java:1129)
    at android.widget.TextView.<init>(TextView.java:1125)
        ... 33 more

如何修复此错误。?

1 个答案:

答案 0 :(得分:0)

我找到了答案

清单中的MainActivity应使用以下主题

android:theme="@style/Theme.AppCompat.NoActionBar"