wayneeWang 2016-06-17 03:20 采纳率: 10%
浏览 1288

andoid的theme报错,求帮忙

报错: java.lang.RuntimeException: Unable to start receiver com.example.broadcastbestpractice.ForceOfflineReceiver: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme
(or descendant) with this activity.

全部活动继承的是import android.support.v7.app.AppCompatActivity;

 /**
 * Created by Administrator on 2016/6/15.
 */
public class BaseActivity extends AppCompatActivity {

配置文件:

     package="com.example.broadcastbestpractice">

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat">

        <activity android:name=".LoginActivity"
            android:label="@string/app_name">

            <intent-filter>
                <action android:name="android.intent.action.MAIN"
                    />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>
        </activity>

        <activity android:name=".MainActivity">

        </activity>

        <receiver android:name=".ForceOfflineReceiver">
            <intent-filter>
                <action android:name="com.example.broadcastbestpractice.FORCE_OFFLINE"/>
            </intent-filter>

        </receiver>
    </application>


接收器:

 package com.example.broadcastbestpractice;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

import android.support.v7.app.AlertDialog;
import android.view.WindowManager;

/**
 * Created by Administrator on 2016/6/15.
 */
public class ForceOfflineReceiver extends BroadcastReceiver {
    @Override

    public void onReceive(final Context context, Intent intent) {
       AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);

        dialogBuilder.setTitle("Warning");
        dialogBuilder.setMessage("You are forced to be offline.Please try to login again.");

        dialogBuilder.setCancelable(false);
        dialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                ActivityCollector.finishAll();

                Intent intent = new Intent(context,LoginActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }
        });

        AlertDialog alertDialog = dialogBuilder.create();//创建对话框

        //设置对话框类型
        alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        alertDialog.show();
    }
}

  • 写回答

1条回答 默认 最新

  • Demolcm 2016-06-17 03:55
    关注

    楼主你看一下
    http://blog.csdn.net/lincyang/article/details/42673151
    是否对你有用
    如果不是很有用建议你换一个方法来实现你的对话框
    希望采纳

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?