Changes

Jump to: navigation, search

An Android 6 HTML and Web Content Printing Example

2,579 bytes removed, 21:36, 5 January 2016
no edit summary
</pre>
<google>ADSDAQBOX_FLOW</google>
Switch back to Design mode and, from the Widgets section of the palette, drag and drop a WebView object onto the center of the device screen layout. Using either the Properties panel or the Designer toolbar buttons, change the layout_width and layout_height properties of the WebView to match_parent so that it fills the entire layout canvas as outlined in Figure 59-3:
 
[[Image:android_studio_web_print_ui_1.4.png]]
 
Figure 59-3
 
 
Double-click on the newly added WebView instance, and change the ID of the view to myWebView.
 
Before proceeding to the next step of this tutorial, an additional permission needs to be added to the project to enable the WebView object to access the internet and download a web page for printing. Add this permission by locating the AndroidManifest.xml file in the Project tool window and double clicking on it to load it into the editing panel. Once loaded, edit the XML content to add the appropriate permission line as shown in the following listing:
 
<pre>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ebookfrenzy.webprint" >
 
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".WebPrintActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
 
<category android:name=
"android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
 
</manifest>
</pre>
<google>BUY_ANDROID_STUDIO6</google>
 
== Designing the User Interface Layout ==
 
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.
 
Switch to the XML view by clicking on the Text tab located along the lower edge of the Designer panel and remove the padding properties from the file so that the WebView will extend to the edges of the display when added to the layout:
 
<pre>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".WebPrintActivity">
 
</RelativeLayout>
</pre>
 
Switch back to Design mode and, from the Widgets section of the palette, drag and drop a WebView object onto the center of the device screen layout. Using either the Properties panel or the Designer toolbar buttons, change the layout_width and layout_height properties of the WebView to match_parent so that it fills the entire layout canvas as outlined in Figure 59-3:

Navigation menu