获取类型attr的错误预期资源

时间:2015-06-24 11:39:50

标签: android lockscreen home-button

我正在尝试使用Home Key Locker https://github.com/shaobin0604/Android-HomeKey-Locker 我希望能够检测并阻止锁屏上的主屏幕按钮单击。大多数答案提到它不能被禁用。

这是HomeKeyLocker类:​​

 package com.example.harshilshah.screenonoff;

  import android.app.Activity;
  import android.app.AlertDialog;
  import android.os.Bundle;
  import android.view.Gravity;
  import android.view.MotionEvent;
  import android.view.WindowManager;
  import android.widget.FrameLayout;

  import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
  import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
  import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;


public class HomeKeyLocker {
private OverlayDialog mOverlayDialog;

public void lock(Activity activity) {
    if (mOverlayDialog == null) {
        mOverlayDialog = new OverlayDialog(activity);
        mOverlayDialog.show();
    }
}

public void unlock() {
    if (mOverlayDialog != null) {
        mOverlayDialog.dismiss();
        mOverlayDialog = null;
    }
}

  public static class OverlayDialog extends AlertDialog {

    public OverlayDialog(Activity activity) {
        super(activity, R.style.OverlayDialog);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.type = TYPE_SYSTEM_ERROR;
        params.dimAmount = 0.0F; // transparent
        params.width = 0;
        params.height = 0;
        params.gravity = Gravity.BOTTOM;
        getWindow().setAttributes(params);
        getWindow().setFlags(FLAG_SHOW_WHEN_LOCKED | FLAG_NOT_TOUCH_MODAL, 0xffffff);
        setOwnerActivity(activity);
        setCancelable(false);
    }

    public final boolean dispatchTouchEvent(MotionEvent motionevent) {
        return true;
    }

    protected final void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        FrameLayout framelayout = new FrameLayout(getContext());
        framelayout.setBackgroundColor(0);
        setContentView(framelayout);
    }
  }
}

这是styles.xml

 <resources>

 <!-- Base application theme. -->
 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
 </style>

<style name="OverlayDialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowIsTranslucent">false</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

</resources>

我收到错误以下行中的Attr类型的预期资源

 public OverlayDialog(Activity activity) {
        super(activity, R.style.OverlayDialog);//ERROR

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我刚遇到这个问题。导致它的原因是我导入了<script type="text/javascript"> function japa(r) { $("#Tamfan").html(""); $.ajax({ context : this, url : 'file.php?id='+r, type : 'GET', dataType: 'html', success : function(pesan){ $("#Tamfan").html(pesan); }, }); } </script> ,而不是已在我的应用中定义的android.R class类。所以它没有使用在我的应用程序的值中定义的 styles.xml ,其中实现了OverlayDialog,但是在Android系统中定义的标准版本显然没有它。删除R并添加import android.R后,工作正常。