<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8764138735232466668</id><updated>2026-10-11T15:51:37.822-07:00</updated><title type='text'>Android Programming</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://devemat-androidprogramming.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8764138735232466668/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://devemat-androidprogramming.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8764138735232466668.post-8534727580596485389</id><published>2013-05-04T12:01:00.000-07:00</published><updated>2013-05-04T12:01:32.864-07:00</updated><title type='text'>WebView Progress Bar</title><content type='html'>This post is going to show how to add a progress bar to a WebView, which can let the user know that there is something going on while your page loads. Some newer versions of Android may already have this built in, but the older versions of Android did not.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Basic WebView&lt;/b&gt;&lt;br /&gt;
First we need to setup a basic WebView to load a page. In your main activity add the following code to create a WebView:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;package com.test.webviewprogbar;



import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.webkit.WebView;



public class MainActivity extends Activity {



WebView mWebView;


&amp;nbsp; &amp;nbsp; @Override

&amp;nbsp; &amp;nbsp; public void onCreate(Bundle savedInstanceState) {

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setContentView(R.layout.activity_main);

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mWebView = (WebView)findViewById(R.id.webview);

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mWebView.loadUrl(&quot;http://devemat-androidprogramming.blogspot.com/&quot;);

&amp;nbsp; &amp;nbsp; }



&amp;nbsp; &amp;nbsp; @Override

&amp;nbsp; &amp;nbsp; public boolean onCreateOptionsMenu(Menu menu) {

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; getMenuInflater().inflate(R.menu.activity_main, menu);

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;

&amp;nbsp; &amp;nbsp; }

}&lt;/pre&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
Now in the activity_main.xml make sure it looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;

&amp;lt;WebView &amp;nbsp;xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;

&amp;nbsp; &amp;nbsp; android:id=&quot;@+id/webview&quot;

&amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;

&amp;nbsp; &amp;nbsp; android:layout_height=&quot;fill_parent&quot;

&amp;nbsp;

/&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
In the AndroidManifest.xml make sure to add internet permission when loading webpages. Add it after the end application tag, like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;

&amp;nbsp; &amp;nbsp; package=&quot;com.test.webviewprogbar&quot;

&amp;nbsp; &amp;nbsp; android:versionCode=&quot;1&quot;

&amp;nbsp; &amp;nbsp; android:versionName=&quot;1.0&quot; &amp;gt;



&amp;nbsp; &amp;nbsp; &amp;lt;uses-sdk

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:minSdkVersion=&quot;1&quot;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:targetSdkVersion=&quot;15&quot; /&amp;gt;



&amp;nbsp; &amp;nbsp; &amp;lt;application

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:icon=&quot;@drawable/ic_launcher&quot;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:label=&quot;@string/app_name&quot;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:theme=&quot;@style/AppTheme&quot; &amp;gt;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;activity

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:name=&quot;.MainActivity&quot;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:label=&quot;@string/title_activity_main&quot; &amp;gt;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;intent-filter&amp;gt;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;action android:name=&quot;android.intent.action.MAIN&quot; /&amp;gt;



&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&amp;gt;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/intent-filter&amp;gt;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/activity&amp;gt;

&amp;nbsp; &amp;nbsp; &amp;lt;/application&amp;gt;

&amp;lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&amp;gt;

&amp;lt;/manifest&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Now is a good time to verify that the code is working okay so far.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Add Progress Bar&lt;/b&gt;&lt;br /&gt;
The following bit of code is all that is needed now to load a progress bar. You can also change how quickly it loads by changing the 100 to another number.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;final Activity myActivity = this;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;

&amp;nbsp; mWebView.setWebChromeClient(new WebChromeClient(){

       public void onProgressChanged(WebView view, int progress){

       myActivity.setProgress(progress * 100);

}

});

&lt;/pre&gt;
&lt;br /&gt;
Here is how MainActivity.java should look after adding the new code:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;package com.test.webviewprogbar;



import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.webkit.WebChromeClient;

import android.webkit.WebView;



public class MainActivity extends Activity {



WebView mWebView;



&amp;nbsp; &amp;nbsp; @Override

&amp;nbsp; &amp;nbsp; public void onCreate(Bundle savedInstanceState) {

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setContentView(R.layout.activity_main);

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mWebView = (WebView)findViewById(R.id.webview);

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; final Activity myActivity = this;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mWebView.setWebChromeClient(new WebChromeClient(){

public void onProgressChanged(WebView view, int progress){

myActivity.setProgress(progress * 100);

}

});

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mWebView.loadUrl(&quot;http://devemat-androidprogramming.blogspot.com/&quot;);

&amp;nbsp; &amp;nbsp; }



&amp;nbsp; &amp;nbsp; @Override

&amp;nbsp; &amp;nbsp; public boolean onCreateOptionsMenu(Menu menu) {

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; getMenuInflater().inflate(R.menu.activity_main, menu);

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;

&amp;nbsp; &amp;nbsp; }

}&lt;/pre&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://devemat-androidprogramming.blogspot.com/feeds/8534727580596485389/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://devemat-androidprogramming.blogspot.com/2013/05/webview-progress-bar.html#comment-form' title='18 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8764138735232466668/posts/default/8534727580596485389'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8764138735232466668/posts/default/8534727580596485389'/><link rel='alternate' type='text/html' href='http://devemat-androidprogramming.blogspot.com/2013/05/webview-progress-bar.html' title='WebView Progress Bar'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>18</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8764138735232466668.post-846466139272548768</id><published>2012-03-18T10:54:00.003-07:00</published><updated>2012-03-18T12:49:37.834-07:00</updated><title type='text'>Search text within a WebView</title><content type='html'>This article is to explain how to search for text within a WebView. The functions used are built into the WebView Class already. This article will show the classes used for search within a WebView, and also show how to create user interface functionality similar to the web browser on Android phones. The search functionality will include a text box for search word entry, a next button, close button, and text highlighting of search words found within the WebView. Here is a screenshot of what it will look like once we are finished:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibBueDIox28zGrf89Ee5mR_6gLHkUlFGfYJvX4jgv4aOd4XNVG-WC6ZDWg2PByLBybjFmJgolqVBG27HPw3tztNLlNfYH9smiReYeW1aQqZscW53CEoWpww_QIfejLQWjKHPMSeLkdDXWG/s1600/SearchDemo.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibBueDIox28zGrf89Ee5mR_6gLHkUlFGfYJvX4jgv4aOd4XNVG-WC6ZDWg2PByLBybjFmJgolqVBG27HPw3tztNLlNfYH9smiReYeW1aQqZscW53CEoWpww_QIfejLQWjKHPMSeLkdDXWG/s320/SearchDemo.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Basic WebView&lt;/b&gt;&lt;br /&gt;
First, we are going to want to set up a WebView to add search functionality to.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SearchDemoActivity.java&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;package com.search.demo;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class SearchDemoActivity extends Activity {
WebView mWebView;
&amp;nbsp; &amp;nbsp; /** Called when the activity is first created. */
&amp;nbsp; &amp;nbsp; @Override
&amp;nbsp; &amp;nbsp; public void onCreate(Bundle savedInstanceState) {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setContentView(R.layout.main);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mWebView = (WebView)findViewById(R.id.webview);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mWebView.loadUrl(&quot;http://devemat-androidprogramming.blogspot.com/&quot;);
&amp;nbsp; &amp;nbsp; }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;main.xml&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;WebView &amp;nbsp;xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
&amp;nbsp; &amp;nbsp; android:id=&quot;@+id/webview&quot;
&amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;
&amp;nbsp; &amp;nbsp; android:layout_height=&quot;fill_parent&quot;
&amp;nbsp; 
/&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SearchDemo Manifest&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
In your manifest make sure to add the internet permission so your web page loads.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
&amp;nbsp; &amp;nbsp; &amp;nbsp; package=&quot;com.search.demo&quot;
&amp;nbsp; &amp;nbsp; &amp;nbsp; android:versionCode=&quot;1&quot;
&amp;nbsp; &amp;nbsp; &amp;nbsp; android:versionName=&quot;1.0&quot;&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;lt;uses-sdk android:minSdkVersion=&quot;8&quot; /&amp;gt;

&amp;nbsp; &amp;nbsp; &amp;lt;application android:icon=&quot;@drawable/icon&quot; android:label=&quot;@string/app_name&quot;&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;activity android:name=&quot;.SearchDemoActivity&quot;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:label=&quot;@string/app_name&quot;&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;intent-filter&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;action android:name=&quot;android.intent.action.MAIN&quot; /&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/intent-filter&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/activity&amp;gt;

&amp;nbsp; &amp;nbsp; &amp;lt;/application&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&amp;gt;
&amp;lt;/manifest&amp;gt;
&lt;/pre&gt;Test to make sure that your WebView is functioning correctly before moving on to the next step.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Add A Menu Option for Search&lt;/b&gt;&lt;br /&gt;
Now that we have a webpage loaded in our WebView we will add a search menu option for when the user wants to search the web page. Here is what our SearchDemoActivity.java looks like with the search menu option added:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SearchDemoActivity.java with Search Menu Option&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;package com.search.demo;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;

public class SearchDemoActivity extends Activity {
WebView mWebView;
&amp;nbsp; &amp;nbsp; /** Called when the activity is first created. */
&amp;nbsp; &amp;nbsp; @Override
&amp;nbsp; &amp;nbsp; public void onCreate(Bundle savedInstanceState) {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setContentView(R.layout.main);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mWebView = (WebView)findViewById(R.id.webview);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mWebView.loadUrl(&quot;http://devemat-androidprogramming.blogspot.com/&quot;);
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; private static final int SEARCH_MENU_ID = Menu.FIRST;
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; @Override
&amp;nbsp; &amp;nbsp; public boolean onCreateOptionsMenu(Menu menu){
&amp;nbsp; &amp;nbsp; super.onCreateOptionsMenu(menu);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; menu.add(0, SEARCH_MENU_ID, 0, &quot;Search&quot;);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; return true;
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; public boolean onPrepareOptionsMenu(Menu menu){
&amp;nbsp; &amp;nbsp;  super.onPrepareOptionsMenu(menu);
&amp;nbsp; &amp;nbsp; return true;
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; public boolean onOptionsItemSelected(MenuItem item){
&amp;nbsp; &amp;nbsp; switch(item.getItemId()){
&amp;nbsp; &amp;nbsp; case SEARCH_MENU_ID:
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; return true;
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; return true;
&amp;nbsp; &amp;nbsp; }
}
&lt;/pre&gt;&lt;b&gt;Search User Interface&lt;/b&gt;&lt;br /&gt;
Now that we have a webpage to search and a menu option to select search we need to create a user interface to get the search word from the user. Also we will enable the user to cycle through the found words and to close the search interface. To do this I create a dynamic Linear Layout. I&#39;m sure you could create a static UI using XML, but this is the way that made since to me. First add a Linear Layout to our main.xml:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Main.xml with Linear Layout&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;RelativeLayout
xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;fill_parent&quot;
&amp;gt;
&amp;lt;WebView 
&amp;nbsp; &amp;nbsp; android:id=&quot;@+id/webview&quot;
&amp;nbsp; &amp;nbsp;android:layout_width=&quot;fill_parent&quot;
&amp;nbsp; &amp;nbsp; android:layout_height=&quot;fill_parent&quot;
&amp;nbsp; 
/&amp;gt;

&amp;lt;LinearLayout
android:orientation=&quot;horizontal&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:id=&quot;@+id/layoutId&quot;

&amp;gt;&amp;lt;/LinearLayout&amp;gt;


&amp;lt;/RelativeLayout&amp;gt;
&lt;/pre&gt;Next we will have our Edit Box and buttons appear when the user selects search from the options menu. We will add a function called search to contain all of our search functionality. Here is what our SearchDemoActivity.java looks like with the added Linear Layout items:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SearchDemoActivity.java with Edit Box and Buttons&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;&amp;nbsp;package com.search.demo;


import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class SearchDemoActivity extends Activity {
WebView mWebView;
private LinearLayout container;
private Button nextButton, closeButton;
private EditText findBox;
&amp;nbsp; &amp;nbsp; /** Called when the activity is first created. */
&amp;nbsp; &amp;nbsp; @Override
&amp;nbsp; &amp;nbsp; public void onCreate(Bundle savedInstanceState) {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setContentView(R.layout.main);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mWebView = (WebView)findViewById(R.id.webview);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mWebView.loadUrl(&quot;http://devemat-androidprogramming.blogspot.com/&quot;);
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; private static final int SEARCH_MENU_ID = Menu.FIRST;
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; @Override
&amp;nbsp; &amp;nbsp; public boolean onCreateOptionsMenu(Menu menu){
&amp;nbsp; &amp;nbsp; super.onCreateOptionsMenu(menu);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; menu.add(0, SEARCH_MENU_ID, 0, &quot;Search&quot;);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; return true;
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; public boolean onPrepareOptionsMenu(Menu menu){
&amp;nbsp; &amp;nbsp; super.onPrepareOptionsMenu(menu);
&amp;nbsp; &amp;nbsp; return true;
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; public boolean onOptionsItemSelected(MenuItem item){
&amp;nbsp; &amp;nbsp; switch(item.getItemId()){
&amp;nbsp; &amp;nbsp; case SEARCH_MENU_ID:
&amp;nbsp; &amp;nbsp; search();
&amp;nbsp; &amp;nbsp; return true;
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; return true;
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; public void search(){
&amp;nbsp; &amp;nbsp; container = (LinearLayout)findViewById(R.id.layoutId);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; nextButton = new Button(this);
&amp;nbsp; &amp;nbsp; nextButton.setText(&quot;Next&quot;);
&amp;nbsp; &amp;nbsp; container.addView(nextButton);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; closeButton = new Button(this);
&amp;nbsp; &amp;nbsp; closeButton.setText(&quot;Close&quot;);
&amp;nbsp; &amp;nbsp; container.addView(closeButton);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; findBox = new EditText(this);
findBox.setMinEms(30);
findBox.setSingleLine(true);
container.addView(findBox);
&amp;nbsp; &amp;nbsp; }
}
&lt;/pre&gt;&lt;b&gt;Search Functionality&lt;/b&gt;&lt;br /&gt;
Now we just need to add functionality to our buttons and edit box. To do this we will use the WebView built in search functionality. Most notably is the WebView.findall(). This is going to do the search functionality for us. Then we just have to provide the button functionality. To do this we will use WebView.findnext() and LinearLayout.removeAllViews(). We will also add a hint that is displayed in our edit box using EditText.setHint(). Here is what our SearchDemoActivity.java looks like with the added search functionality:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;SearchDemoActivity.java with Search Functionality&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;package com.search.demo;


import java.lang.reflect.Method;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class SearchDemoActivity extends Activity {
WebView mWebView;
private LinearLayout container;
private Button nextButton, closeButton;
private EditText findBox;
&amp;nbsp; &amp;nbsp; /** Called when the activity is first created. */
&amp;nbsp; &amp;nbsp; @Override
&amp;nbsp; &amp;nbsp; public void onCreate(Bundle savedInstanceState) {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setContentView(R.layout.main);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mWebView = (WebView)findViewById(R.id.webview);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mWebView.loadUrl(&quot;http://devemat-androidprogramming.blogspot.com/&quot;);
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; private static final int SEARCH_MENU_ID = Menu.FIRST;
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; @Override
&amp;nbsp; &amp;nbsp; public boolean onCreateOptionsMenu(Menu menu){
&amp;nbsp; &amp;nbsp; super.onCreateOptionsMenu(menu);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; menu.add(0, SEARCH_MENU_ID, 0, &quot;Search&quot;);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; return true;
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; public boolean onPrepareOptionsMenu(Menu menu){
&amp;nbsp; &amp;nbsp; super.onPrepareOptionsMenu(menu);
&amp;nbsp; &amp;nbsp; return true;
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; public boolean onOptionsItemSelected(MenuItem item){
&amp;nbsp; &amp;nbsp; switch(item.getItemId()){
&amp;nbsp; &amp;nbsp; case SEARCH_MENU_ID:
&amp;nbsp; &amp;nbsp; search();
&amp;nbsp; &amp;nbsp; return true;
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; return true;
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; &amp;nbsp; public void search(){
&amp;nbsp; &amp;nbsp; container = (LinearLayout)findViewById(R.id.layoutId);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; nextButton = new Button(this);
&amp;nbsp; &amp;nbsp; nextButton.setText(&quot;Next&quot;);
&amp;nbsp; &amp;nbsp; nextButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
mWebView.findNext(true);
}
});
&amp;nbsp; &amp;nbsp; container.addView(nextButton);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; closeButton = new Button(this);
&amp;nbsp; &amp;nbsp; closeButton.setText(&quot;Close&quot;);
&amp;nbsp; &amp;nbsp; closeButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
container.removeAllViews();

}
});
&amp;nbsp; &amp;nbsp; container.addView(closeButton);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; findBox = new EditText(this);
findBox.setMinEms(30);
findBox.setSingleLine(true);
findBox.setHint(&quot;Search&quot;);

findBox.setOnKeyListener(new OnKeyListener(){
public boolean onKey(View v, int keyCode, KeyEvent event){
if((event.getAction() == KeyEvent.ACTION_DOWN) &amp;amp;&amp;amp; ((keyCode == KeyEvent.KEYCODE_ENTER))){
mWebView.findAll(findBox.getText().toString());

try{
Method m = WebView.class.getMethod(&quot;setFindIsUp&quot;, Boolean.TYPE);
m.invoke(mWebView, true);
}catch(Exception ignored){}
}
return false;
}
});

container.addView(findBox);
&amp;nbsp; &amp;nbsp; }
}
&lt;/pre&gt;And that&#39;s all there is to it. Your WebView should now have complete search functionality with search word highlighting similar to a web browser.</content><link rel='replies' type='application/atom+xml' href='http://devemat-androidprogramming.blogspot.com/feeds/846466139272548768/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://devemat-androidprogramming.blogspot.com/2012/03/search-text-within-webview.html#comment-form' title='27 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8764138735232466668/posts/default/846466139272548768'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8764138735232466668/posts/default/846466139272548768'/><link rel='alternate' type='text/html' href='http://devemat-androidprogramming.blogspot.com/2012/03/search-text-within-webview.html' title='Search text within a WebView'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibBueDIox28zGrf89Ee5mR_6gLHkUlFGfYJvX4jgv4aOd4XNVG-WC6ZDWg2PByLBybjFmJgolqVBG27HPw3tztNLlNfYH9smiReYeW1aQqZscW53CEoWpww_QIfejLQWjKHPMSeLkdDXWG/s72-c/SearchDemo.png" height="72" width="72"/><thr:total>27</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8764138735232466668.post-1848647101147827184</id><published>2012-02-20T16:27:00.000-08:00</published><updated>2012-02-20T16:27:58.367-08:00</updated><title type='text'>Creating a Hi-Res 512x512 Launcher Icon</title><content type='html'>Here is a tool that I have found useful:&lt;br /&gt;
&lt;a href=&quot;http://converticon.com/&quot;&gt;http://converticon.com/&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
This online tool enables you to upload your Android Launcher icon and it will convert it to the size that you want. I use this for when I need to create that pesky 512x512 image that is required to submit an app to the Android Market.&lt;br /&gt;
&lt;br /&gt;
It has a simple online interface:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjU5tp2UgyCnnivqN9WEYkuyCYhI53Dl2KXnCyW_w9uKjb5JygG6s4ZF8dQlrkj5UJ9HQnkX0yuj_DB8WT79iA6vaDuJu5Dd8cFKyvbx3B9oa9QN35_KdrJufn1Jzl5DY1wUOrqqAKRBbN3/s1600/converticon+screenshot+1.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;274&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjU5tp2UgyCnnivqN9WEYkuyCYhI53Dl2KXnCyW_w9uKjb5JygG6s4ZF8dQlrkj5UJ9HQnkX0yuj_DB8WT79iA6vaDuJu5Dd8cFKyvbx3B9oa9QN35_KdrJufn1Jzl5DY1wUOrqqAKRBbN3/s320/converticon+screenshot+1.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Just click the Get Started button and then pick your launcher icon. Use the drop down box on the bottom left when browsing for your icon to choose a different file type. The default is Icon (ico). I usually have to set it to Image (png, gif, jpeg). Once you have selected your launcher icon, select the Export button.&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Now you will want to select the 512x512 option to get your hi-res launcher icon:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggJwLzJgxlkLntYCT2Pz-foDQfbdEnusl2LId0NncJIyRiMDlGD4XmqLnhUqyfz8y2tE-uBguVEORP6lsG8CWVnyp6Murvz8Ff088Tv33cCHz-R9mpF1C1OVi6lF7E-ZGIczrtg30GNCoe/s1600/converticon+screenshot+2.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;282&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggJwLzJgxlkLntYCT2Pz-foDQfbdEnusl2LId0NncJIyRiMDlGD4XmqLnhUqyfz8y2tE-uBguVEORP6lsG8CWVnyp6Murvz8Ff088Tv33cCHz-R9mpF1C1OVi6lF7E-ZGIczrtg30GNCoe/s320/converticon+screenshot+2.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;Once you have selected the size you want your icon to be, select Save As.&lt;br /&gt;
&lt;br /&gt;
After you save it, just upload it to Android Market and now you have that pesky hi-res requirement out of the way.</content><link rel='replies' type='application/atom+xml' href='http://devemat-androidprogramming.blogspot.com/feeds/1848647101147827184/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://devemat-androidprogramming.blogspot.com/2012/02/creating-hi-res-512x512-launcher-icon.html#comment-form' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8764138735232466668/posts/default/1848647101147827184'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8764138735232466668/posts/default/1848647101147827184'/><link rel='alternate' type='text/html' href='http://devemat-androidprogramming.blogspot.com/2012/02/creating-hi-res-512x512-launcher-icon.html' title='Creating a Hi-Res 512x512 Launcher Icon'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjU5tp2UgyCnnivqN9WEYkuyCYhI53Dl2KXnCyW_w9uKjb5JygG6s4ZF8dQlrkj5UJ9HQnkX0yuj_DB8WT79iA6vaDuJu5Dd8cFKyvbx3B9oa9QN35_KdrJufn1Jzl5DY1wUOrqqAKRBbN3/s72-c/converticon+screenshot+1.PNG" height="72" width="72"/><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8764138735232466668.post-3283563043420495116</id><published>2011-06-05T14:27:00.000-07:00</published><updated>2011-06-05T14:36:28.266-07:00</updated><title type='text'>Selecting Text with a WebView</title><content type='html'>The following explains how to copy text from a WebView to the clipboard.  &lt;br /&gt;
&lt;br /&gt;
First let&#39;s create a simple app that uses a WebView to load a web page. If any of the following doesn&#39;t make sense refer to the Android tutorial&amp;nbsp;&lt;a href=&quot;http://developer.android.com/resources/tutorials/views/hello-webview.html&quot;&gt;http://developer.android.com/resources/tutorials/views/hello-webview.html&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;main.xml&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;WebView &amp;nbsp;xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
&amp;nbsp; &amp;nbsp; android:id=&quot;@+id/webview&quot;
&amp;nbsp; &amp;nbsp; android:layout_width=&quot;fill_parent&quot;
&amp;nbsp; &amp;nbsp; android:layout_height=&quot;fill_parent&quot;
&amp;nbsp; &amp;nbsp;
/&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;a href=&quot;http://developer.android.com/resources/tutorials/views/hello-webview.html&quot;&gt;&lt;/a&gt;MainActivity.java&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;package com.Demo.SelectText;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class MainActivity extends Activity {
   WebView mWebView;

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      mWebView = (WebView)findViewById(R.id.webview);
      mWebView.loadUrl(&quot;http://devemat-androidprogramming.blogspot.com/&quot;);

   }
}
&lt;/pre&gt;&lt;br /&gt;
Now remember to set the internet permission in your Manifest after &lt;br /&gt;
&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;/application&amp;gt;&lt;/pre&gt;&lt;pre class=&quot;xml&quot; name=&quot;code&quot;&gt;&amp;lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&amp;gt;&lt;/pre&gt;&lt;br /&gt;
In order to allow the user to enable the select text feature we are going to make it a menu option. So let&#39;s set up our menu in the main activity. Refer to the following link for more information on Menu&#39;s:&lt;br /&gt;
&lt;a href=&quot;http://developer.android.com/guide/topics/ui/menus.html&quot;&gt;http://developer.android.com/guide/topics/ui/menus.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Select Text Menu Option&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;private static final int SELECTTEXT_MENU_ID = Menu.FIRST;
&amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; @Override
&amp;nbsp; &amp;nbsp; public boolean onCreateOptionsMenu(Menu menu){
&amp;nbsp; &amp;nbsp;    super.onCreateOptionsMenu(menu);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp;    menu.add(0, SELECTTEXT_MENU_ID, 0, &quot;Select Text&quot;);
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp;    return true;
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; public boolean onPrepareOptionsMenu(Menu menu){
&amp;nbsp; &amp;nbsp;    super.onPrepareOptionsMenu(menu);
&amp;nbsp; &amp;nbsp;    return true;
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; public boolean onOptionsItemSelected(MenuItem item){
&amp;nbsp; &amp;nbsp;    switch(item.getItemId()){
&amp;nbsp; &amp;nbsp;    case SELECTTEXT_MENU_ID:
&amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp;       return true;
&amp;nbsp; &amp;nbsp;    }
&amp;nbsp; &amp;nbsp;    return true;
&amp;nbsp; &amp;nbsp; }
&lt;/pre&gt;&lt;br /&gt;
Now we just need to create our Select Text method and call it when the Select Text menu option is selected by the user.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Select Text method&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;public void SelectText(){
  try{
    KeyEvent shiftPressEvent = 
       new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, 
       KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
   shiftPressEvent.dispatch(mWebView);
  }catch(Exception e){
   throw new AssertionError(e);
  }
 }
&lt;/pre&gt;&lt;br /&gt;
The Select Text method activates the left shift key, which in Android is the select text key. Not all phones have a keyboard so we press the shift key for the user by using a KeyEvent.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Now just call the Select Text method when the user selects the option under the menu:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;public boolean onOptionsItemSelected(MenuItem item){
     switch(item.getItemId()){
     case SELECTTEXT_MENU_ID:
      SelectText();
      return true;
     }
     return true;
    }
&lt;/pre&gt;&lt;br /&gt;
And that&#39;s it. Your application can now copy text to the clipboard. After the Select Text option is chosen under menu the user drags her finger across the text. Once she takes her finger off the screen, the selected text is copied to the clipboard. Also, a nice toast message is displayed telling the user that the text was copied to the clipboard.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Here is what your Main Activity should look like:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;java&quot; name=&quot;code&quot;&gt;package com.Demo.SelectText;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;

public class MainActivity extends Activity {
 WebView mWebView;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mWebView = (WebView)findViewById(R.id.webview);
        mWebView.loadUrl(&quot;http://devemat-androidprogramming.blogspot.com/&quot;);
        
    }
    
    private static final int SELECTTEXT_MENU_ID = Menu.FIRST;
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu){
     super.onCreateOptionsMenu(menu);
     
     menu.add(0, SELECTTEXT_MENU_ID, 0, &quot;Select Text&quot;);
     
     return true;
    }
    
    public boolean onPrepareOptionsMenu(Menu menu){
     super.onPrepareOptionsMenu(menu);
     return true;
    }
    
    public boolean onOptionsItemSelected(MenuItem item){
     switch(item.getItemId()){
     case SELECTTEXT_MENU_ID:
          SelectText();
          return true;
     }
     return true;
    }

    public void SelectText(){
    try{
      KeyEvent shiftPressEvent = 
               new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,     
               KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
      shiftPressEvent.dispatch(mWebView);
  }catch(Exception e){
      throw new AssertionError(e);
  }
 }
}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://devemat-androidprogramming.blogspot.com/feeds/3283563043420495116/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://devemat-androidprogramming.blogspot.com/2011/06/selecting-text-with-webview.html#comment-form' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8764138735232466668/posts/default/3283563043420495116'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8764138735232466668/posts/default/3283563043420495116'/><link rel='alternate' type='text/html' href='http://devemat-androidprogramming.blogspot.com/2011/06/selecting-text-with-webview.html' title='Selecting Text with a WebView'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8764138735232466668.post-6139368666546708711</id><published>2011-06-05T12:53:00.000-07:00</published><updated>2011-06-05T12:53:26.067-07:00</updated><title type='text'>test</title><content type='html'>testing code syntax highlighting&lt;br /&gt;
&lt;br /&gt;
&lt;pre name=&quot;code&quot; class=&quot;cpp&quot;&gt;public class MainActivity extends ListActivity {
&amp;nbsp; &amp;nbsp; /** Called when the activity is first created. */
&amp;nbsp; &amp;nbsp; @Override
&amp;nbsp; &amp;nbsp; public void onCreate(Bundle savedInstanceState) {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://devemat-androidprogramming.blogspot.com/feeds/6139368666546708711/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://devemat-androidprogramming.blogspot.com/2011/06/test.html#comment-form' title='26 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8764138735232466668/posts/default/6139368666546708711'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8764138735232466668/posts/default/6139368666546708711'/><link rel='alternate' type='text/html' href='http://devemat-androidprogramming.blogspot.com/2011/06/test.html' title='test'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>26</thr:total></entry></feed>