我遇到了这个问题,我尝试了很多解决方案,但是它们不起作用。
xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container"/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_menu" />
</android.support.v4.widget.DrawerLayout>
build.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.jakewharton:butterknife:8.8.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="alertDialogTheme">@style/AppTheme.Dialog.Alert</item>
</style>
<style name="AppTheme.Dialog.Alert" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.TextView" />
<style name="AppTheme.TextView.1" parent="AppTheme.TextView">
<item name="android:textSize">15sp</item>
</style>
<style name="AppTheme.TextView.1.White" parent="AppTheme.TextView.1">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="AppTheme.TextView.2" parent="AppTheme.TextView">
<item name="android:textSize">17sp</item>
</style>
<style name="AppTheme.TextView.2.White" parent="AppTheme.TextView.2">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="AppTheme.TextView.2.Dark" parent="AppTheme.TextView.2">
<item name="android:textColor">@color/text_dark</item>
</style>
<style name="AppTheme.TextView.3" parent="AppTheme.TextView">
<item name="android:textSize">19sp</item>
</style>
<style name="AppTheme.TextView.3.White" parent="AppTheme.TextView.3">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="AppTheme.TextView.Clickable">
<item name="android:background">?attr/selectableItemBackground</item>
<item name="android:padding">@dimen/spacing_small</item>
<item name="android:textAllCaps">true</item>
<item name="android:textColor">@color/colorPrimary</item>
<item name="android:textStyle">bold</item>
</style>
<style name="AppTheme.TextView.Clickable.1" parent="AppTheme.TextView.Clickable">
<item name="android:textSize">15sp</item>
</style>
<style name="AppTheme.TextView.Clickable.1.White" parent="AppTheme.TextView.Clickable.1">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="AppTheme.TextView.Clickable.2" parent="AppTheme.TextView.Clickable">
<item name="android:textSize">17sp</item>
</style>
<style name="AppTheme.TextView.Clickable.2.White" parent="AppTheme.TextView.Clickable.2">
<item name="android:textColor">@android:color/white</item>
</style>
MainActivity.java
public class MainActivity extends AppCompatActivity {
@BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.drawer_layout) DrawerLayout drawerLayout;
@BindView(R.id.drawer) NavigationView navigationView;
private ActionBarDrawerToggle drawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
setupDrawer();
if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_container, ShotListFragment.newInstance())
.commit();
}
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void setupDrawer() {
drawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
drawerLayout, /* DrawerLayout object */
R.string.open_drawer, /* "open drawer" description */
R.string.close_drawer /* "close drawer" description */
);
drawerLayout.addDrawerListener(drawerToggle);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
if (item.isChecked()) {
drawerLayout.closeDrawers();
return true;
}
Fragment fragment = null;
switch (item.getItemId()) {
case R.id.drawer_item_home:
fragment = ShotListFragment.newInstance();
setTitle(R.string.title_home);
break;
case R.id.drawer_item_likes:
fragment = ShotListFragment.newInstance();
setTitle(R.string.title_likes);
break;
case R.id.drawer_item_buckets:
fragment = BucketListFragment.newInstance();
setTitle(R.string.title_buckets);
break;
}
drawerLayout.closeDrawers();
if (fragment != null) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commit();
return true;
}
return false;
}
});
}
}
它抛出了以下三个异常:造成原因:
android.view.InflateException:二进制XML文件行#24:二进制XML 文件行#24:错误放大类 android.support.design.widget.NavigationView
任何帮助将不胜感激!
答案 0 :(得分:0)
尝试此代码。
#!/usr/bin/env python3
import io
import os
import shutil
import subprocess
import time
import PyPDF2
import easygui
import numpy as np
import pandas as pd
from PyPDF2 import PdfFileReader, PdfFileWriter
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
from selenium import webdriver
# User to input file
userpath = easygui.fileopenbox()
print('Loading request file:')
print(userpath)
print('\n')
# Read excel file document with 4 columns: Document, Batch Number, Prints, Duplex
documentlist = pd.read_excel(userpath, usecols='A,B,C,D')
df = pd.DataFrame(documentlist)
# Format column Document numbers to 3 digits
df['Document'] = df['Document'].apply(lambda x: '{0:0>3}'.format(x))
# Deactivate Pandas silly message
pd.options.mode.chained_assignment = None
# Convert numeric values to string type FAR-BR-02.XXX
value = 'FAR'
df['Document'] = df['Document'].astype(str)
list = df['Document']
for x in range(len(list)):
if value not in list[x]:
list[x] = 'FAR-BR-02.' + str(list[x])
else:
continue
df['Document'] = list
print(df)
downloadlist = np.unique(list)
print('\n')
print('Your request contains', len(documentlist['Document']), 'documents, of which, ')
print(len(downloadlist), ' are unique (no repeats) to be retrieved from Proquis: ')
print('\n')
print(downloadlist)
print('\n')
# Prep a temp folder for downloads
# Check if the temp folder exists otherwise, create it
temppath = 'C:/pdfstampertemp/'
if not os.path.exists(temppath):
os.makedirs(temppath)
# Check temp folder is empty otherwise, clean it
if os.listdir(temppath) != []:
fileList = os.listdir(temppath)
for fileName in fileList:
os.remove(temppath + fileName)
# Download files from SSL Proquis using Chromedriver
print('Downloading files from Proquis. Authenticate if required.')
chrome_options = webdriver.ChromeOptions()
preferences = {"download.default_directory": 'C:\pdfstampertemp',
"directory_upgrade": True,
"download.prompt_for_download": False,
"safebrowsing.enabled": True}
chrome_options.add_experimental_option("prefs", preferences)
driver = webdriver.Chrome(chrome_options=chrome_options,
executable_path=r'chromedriver.exe')
url = 'https://proquis.btgplc.com/viewdocument.aspx?DOCNO='
urllist = downloadlist
for x in range(len(downloadlist)):
urllist[x] = url + str(downloadlist[x])
driver.get(urllist[x])
print('Download completed!')
print ('\n')
time.sleep(1)
driver.quit()
# Decrypt downloaded PDFs
# Copy qpdf to temp directory
print('Preparing PDFs ...')
qpdffiles = ['qpdf.exe','qpdf21.dll','libwinpthread-1.dll','libstdc++-6.dll','libiconv2.dll','libgcc_s_dw2-1.dll']
for x in range(len(qpdffiles)):
shutil.copy2(qpdffiles[x], 'c://pdfstampertemp/' + qpdffiles[x])
# Change cwd to decrypt
installdir = os.getcwd()
os.chdir('c://pdfstampertemp/')
# Call qpdf to decrypt pdfs
workinglist = np.unique(list)
downloadlist = np.unique(list)
for x in range(len(downloadlist)):
downloadlist[x] = downloadlist[x] + '.PDF'
workinglist[x] = 'D' + downloadlist[x]
subprocess.run(["qpdf.exe", "--decrypt", downloadlist[x], workinglist[x]])
print('Ready! Stamping now. This may take some time according with the PDF size. Please wait...')
print('\n')
# Set the cwd back to the install directory
os.chdir(installdir)
# Order the file list by batch number
df = df.sort_values('BatchNo')
# Prep: declare variables and create first stamp headers
inputpdf = 'D' + df['Document'] + '.PDF'
outputpdf = 'SD' + df['Document'] + '.PDF'
batchno = df['BatchNo']
copies = df['Copies']
duplex = df['Single/Double']
stamp = ['StampP.pdf', 'StampL.pdf']
# Bach number position in page Portrait and Landscape (x,y)
xp = 400
yp = 780
xl = 640
yl = 530
# Create inital stapms for first entry
batch = str(batchno[1])
# Portrait: create a new PDF with Reportlab, insert the text in set location with specified font
packet = io.BytesIO()
can = canvas.Canvas(packet, pagesize=A4)
can.setFont('Times-Bold', 16)
can.drawString(xp, yp, batch)
can.save()
# move to the beginning of the StringIO buffer
packet.seek(0)
new_pdf = PdfFileReader(packet)
# read the existing PDF
existing_pdf = PdfFileReader(open("BlankStampP.pdf", "rb"))
output = PdfFileWriter()
# add the "watermark" (which is the new pdf) on the existing page
page = existing_pdf.getPage(0)
page.mergePage(new_pdf.getPage(0))
output.addPage(page)
# finally, write "output" to a real file
outputStream = open("StampP.pdf", "wb")
output.write(outputStream)
outputStream.close()
# Landscape: create a new PDF with Reportlab, insert the text in set location with specified font
packet = io.BytesIO()
can = canvas.Canvas(packet, pagesize=A4)
can.setFont('Times-Bold', 16)
can.drawString(xl, yl, batch)
can.save()
# move to the beginning of the StringIO buffer
packet.seek(0)
new_pdf = PdfFileReader(packet)
# read the existing PDF
existing_pdf = PdfFileReader(open("BlankStampL.pdf", "rb"))
output = PdfFileWriter()
# add the "watermark" (which is the new pdf) on the existing page
page = existing_pdf.getPage(0)
page.mergePage(new_pdf.getPage(0))
output.addPage(page)
# finally, write "output" to a real file
outputStream = open("StampL.pdf", "wb")
output.write(outputStream)
outputStream.close()
# Watermark the first PDF
input = temppath + inputpdf[0]
inputfile = open(input, 'rb')
pdfReader = PyPDF2.PdfFileReader(inputfile)
pdfWriter = PyPDF2.PdfFileWriter()
for pageNum in range(pdfReader.numPages):
inputfilePage = pdfReader.getPage(pageNum)
page = pdfReader.getPage(pageNum).mediaBox
if (page.getUpperRight_x() - page.getUpperLeft_x()) > (page.getUpperRight_y() - page.getLowerRight_y()):
stamp ='StampL.pdf'
else:
stamp = 'StampP.pdf'
pdfWatermarkReader = PyPDF2.PdfFileReader(open(stamp, 'rb'))
inputfilePage.mergePage(pdfWatermarkReader.getPage(0))
pdfWriter.addPage(inputfilePage)
resultPdfFile = open(str(temppath + '0' + outputpdf[0]), 'wb')
pdfWriter.write(resultPdfFile)
inputfile.close()
resultPdfFile.close()
# Rest of the files - create new stamp only if needed
for i in range(1,len(inputpdf)):
if batchno[i] != batchno[i-1]:
# Portrait: create a new PDF with Reportlab, insert the text in set location with specified font
packet = io.BytesIO()
can = canvas.Canvas(packet, pagesize=A4)
can.setFont('Times-Bold', 16)
can.drawString(xp, yp, str(batchno[i]))
can.save()
# move to the beginning of the StringIO buffer
packet.seek(0)
new_pdf = PdfFileReader(packet)
# read the existing PDF
existing_pdf = PdfFileReader(open("BlankStampP.pdf", "rb"))
output = PdfFileWriter()
# add the "watermark" (which is the new pdf) on the existing page
page = existing_pdf.getPage(0)
page.mergePage(new_pdf.getPage(0))
output.addPage(page)
# finally, write "output" to a real file
outputStream = open("StampP.pdf", "wb")
output.write(outputStream)
outputStream.close()
# Landscape: create a new PDF with Reportlab, insert the text in set location with specified font
packet = io.BytesIO()
can = canvas.Canvas(packet, pagesize=A4)
can.setFont('Times-Bold', 16)
can.drawString(xl, yl, str(batchno[i]))
can.save()
# move to the beginning of the StringIO buffer
packet.seek(0)
new_pdf = PdfFileReader(packet)
# read the existing PDF
existing_pdf = PdfFileReader(open("BlankStampL.pdf", "rb"))
output = PdfFileWriter()
# add the "watermark" (which is the new pdf) on the existing page
page = existing_pdf.getPage(0)
page.mergePage(new_pdf.getPage(0))
output.addPage(page)
# finally, write "output" to a real file
outputStream = open("StampL.pdf", "wb")
output.write(outputStream)
outputStream.close()
# Stamp them
input = temppath + inputpdf[i]
inputfile = open(input, 'rb')
pdfReader = PyPDF2.PdfFileReader(inputfile)
pdfWriter = PyPDF2.PdfFileWriter()
for pageNum in range(pdfReader.numPages):
inputfilePage = pdfReader.getPage(pageNum)
page = pdfReader.getPage(pageNum).mediaBox
if (page.getUpperRight_x() - page.getUpperLeft_x()) > (page.getUpperRight_y() - page.getLowerRight_y()):
stamp = 'StampL.pdf'
else:
stamp = 'StampP.pdf'
pdfWatermarkReader = PyPDF2.PdfFileReader(open(stamp, 'rb'))
inputfilePage.mergePage(pdfWatermarkReader.getPage(0))
pdfWriter.addPage(inputfilePage)
resultPdfFile = open(str(temppath + str(i) + outputpdf[i]), 'wb')
pdfWriter.write(resultPdfFile)
inputfile.close()
resultPdfFile.close()
print("Stamping has completed.")
print('Script terminated. Have a nice day!')
appbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main2"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main2"
app:menu="@menu/activity_main2_drawer" />
</android.support.v4.widget.DrawerLayout>
nav_hearder.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main2Activity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main2" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
最后,此content.xml布局将此ID传递给所有片段。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/nav_header_desc"
android:paddingTop="@dimen/nav_header_vertical_spacing"
app:srcCompat="@mipmap/ic_launcher_round" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="@string/nav_header_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nav_header_subtitle" />
</LinearLayout>
答案 1 :(得分:0)
添加以下依赖项-
Sub