导航视图应用:菜单构建gradle错误

时间:2017-12-24 06:31:12

标签: gradle build navigationview

我正在尝试在抽屉布局中使用导航视图,但在构建文件时我一直遇到错误。

这是我的xml的样子:

<?php

class Email extends MY_Controller {

    private $enc;
    private $host;
    private $user;
    private $pass;
    private $mailbox;
    private $mbox;

    public function __construct() {
        parent::__construct();

        $this->enc = '/imap/ssl/novalidate-cert';
        $this->host = '****';
        $this->user = '****'; // email
        $this->pass = '****'; // Pass

        $this->mailbox = '{' . $this->host . $this->enc . '}';
        $this->mbox = imap_open($this->mailbox, $this->user, $this->pass);
    }

    public function view() {

        $this->data['message'] = $this->getBody($this->uri->segment(4));

        $this->load->view('template/common/header', $this->data);
        $this->load->view('template/common/nav', $this->data);
        $this->load->view('template/mail/view', $this->data);
        $this->load->view('template/common/footer', $this->data);

        imap_close($this->mbox);
    }

    public function getBody($uid) {
        $body = $this->get_part($uid, "TEXT/HTML");
        // if HTML body is empty, try getting text body
        if ($body == "") {
            $body = $this->get_part($uid, "TEXT/PLAIN");
        }

        $email = $this->user;

        //replace cid with full path to image
        $body = preg_replace_callback(
            '/src="cid:(.*)">/Uims',
            function($m) use($email, $uid){
                //split on @
                $parts = explode('@', $m[1]);
                //replace local path with absolute path
                $img = str_replace($parts[0], '', $parts[0]);
                return "src='$img'>";
           },
        $body);

        return trim(utf8_encode(quoted_printable_decode($body)));
    }    

    private function get_part($uid, $mimetype, $structure = false, $partNumber = false) {
        if (!$structure) {
               $structure = imap_fetchstructure($this->mbox, $uid);
        }
        if ($structure) {
            if ($mimetype == $this->get_mime_type($structure)) {
                if (!$partNumber) {
                    $partNumber = 1;
                }
                $text = imap_fetchbody($this->mbox, $uid, $partNumber, FT_PEEK);
                switch ($structure->encoding) {
                    # 7BIT
                    case 0:
                        return imap_qprint($text);
                    # 8BIT
                    case 1:
                        return imap_8bit($text);
                    # BINARY
                    case 2:
                        return imap_binary($text);
                    # BASE64
                    case 3:
                        return imap_base64($text);
                    # QUOTED-PRINTABLE
                    case 4:
                        return quoted_printable_decode($text);
                    # OTHER
                    case 5:
                        return $text;
                    # UNKNOWN
                    default:
                        return $text;
                }
           }
            // multipart
            if ($structure->type == 1) {
                foreach ($structure->parts as $index => $subStruct) {
                    $prefix = "";
                    if ($partNumber) {
                        $prefix = $partNumber . ".";
                    }
                    $data = $this->get_part($uid, $mimetype, $subStruct, $prefix . ($index + 1));
                    if ($data) {
                        return $data;
                    }
                }
            }
        }
        return false;
    }

    private function get_mime_type($structure) {
        $primaryMimetype = array("TEXT", "MULTIPART", "MESSAGE", "APPLICATION", "AUDIO", "IMAGE", "VIDEO", "OTHER");
        if ($structure->subtype) {
           return $primaryMimetype[(int)$structure->type] . "/" . $structure->subtype;
        }
        return "TEXT/PLAIN";
    }

}

这会导致构建gradle错误。我的菜单如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/contentFrame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!-- The navigation drawer -->
    <android.support.design.widget.NavigationView
        android:id="@+id/navigationView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/navigation_items"
        />
</android.support.v4.widget.DrawerLayout>

当我从navigationView中删除app:菜单时,错误消失了。可能有什么不对?

1 个答案:

答案 0 :(得分:0)

我的修复是我需要添加app:headerLayout =“@ layout / my_header_layout”。