Changes

An Android 6 HTML and Web Content Printing Example

32 bytes added, 19:57, 27 October 2016
m
Text replacement - "<table border="0" cellspacing="0">" to "<table border="0" cellspacing="0" width="100%">"
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="20%">[[Printing with the Android 6 Printing Framework|Previous]]<td align="center">[[Android Studio Development Essentials - Android 6 Edition|Table of Contents]]<td width="20%" align="right">[[A Guide to Android 6 Custom Document Printing|Next]]</td>
<tr>
<td width="20%">Printing with the Android 6 Printing Framework<td align="center"><td width="20%" align="right">A Guide to Android 6 Custom Document Printing</td>
</table>
<hr>
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
As outlined in the previous chapter, entitled [[Printing with the Android 6 Printing Framework]], the Android Printing framework can be used to print both web pages and dynamically created HTML content. While there is much similarity in these two approaches to printing, there are also some subtle differences that need to be taken into consideration. This chapter will work through the creation of two example applications in order to bring some clarity to these two printing options.
== Creating the HTML Printing Example Application ==
}
</pre>
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
The code changes begin by declaring a variable named myWebView in which will be stored a reference to the WebView instance used for the printing operation. Within the onCreate() method, an instance of the WebView class is created to which a WebViewClient instance is then assigned.
== Designing the User Interface Layout ==
<googlehtmlet>ADSDAQBOX_FLOWadsdaqbox_flow</googlehtmlet>
Load the content_web_print.xml layout resource file into the Designer tool if it has not already been loaded and, in Design mode, select and delete the “Hello World!” TextView object.
== Designing the User Interface Layout ==
<googlehtmlet>ADSDAQ_FLOWadsdaqbox_flow</googlehtmlet>
Load the content_web_print.xml layout resource file into the Designer tool if it has not already been loaded and, in Design mode, select and delete the “Hello World!” TextView object.
}
</pre>
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
== Adding the Print Menu Option ==
}
</pre>
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
With the onOptionsItemSelected() method implemented, the activity will call a method named createWebPrintJob() when the print menu option is selected from the overflow menu. The implementation of this method is identical to that used in the previous HTMLPrint project and may now be added to the WebPrintActivity.java file such that it reads as follows:
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
 
<htmlet>ezoicbottom</htmlet>
<hr>
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="20%">[[Printing with the Android 6 Printing Framework|Previous]]<td align="center">[[Android Studio Development Essentials - Android 6 Edition|Table of Contents]]<td width="20%" align="right">[[A Guide to Android 6 Custom Document Printing|Next]]</td>
<tr>
<td width="20%">Printing with the Android 6 Printing Framework<td align="center"><td width="20%" align="right">A Guide to Android 6 Custom Document Printing</td>
</table>