Recently learned the WebView component, wrote a Youdao dictionary of small cases, to share with you for your reference, the specific content as follows
Effect Chart :
Source Download : https://coding.net/u/gxs1225/p/YouDaoDictionary/git
The code is as follows:
Layout
Activity_main.xml
<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 "Android: background= "@drawable/mainbg" android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@ Dimen/activity_horizontal_margin "android:paddingright=" @dimen/activity_horizontal_margin "android:paddingTop=" @ Dimen/activity_vertical_margin "tools:context=". Mainactivity "> <edittext android:id=" @+id/etword "android:layout_width=" Wrap_content "android:layout_height=" "Wrap_content" android:layout_alignparentleft= "true" android:layout_alignparenttop= "true" Android:layout_ margintop= "27DP" android:background= "@android:d rawable/edit_text" android:ems= "android:singleline=" true "Andro Id:textcolor= "#552006" android:textcolorhint= "#782f10" > <requestfocus/> </EditText> <webview A Ndroid:id= "@+id/wvsearchresult" AndroId:layout_width= "Match_parent" android:layout_height= "match_parent" android:layout_alignleft= "@+id/etWord"
android:layout_below= "@+id/etword" android:layout_margintop= "22DP" android:background= "@drawable/bg_roundcorner" Android:textappearance= "Android:attr/textappearancemedium" android:textsize= "25sp"/> <Button android:id= "@ +id/btnsearch "android:layout_width=" wrap_content "android:layout_height=" wrap_content "android:layout_above=" @+ Id/wvsearchresult "android:layout_alignparentright=" true "android:background=" @drawable/ibsearchword "Android:o
nclick= "Searchword"/> </RelativeLayout>
Mainactivity.java
Package com.example.youdaodictionary;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.text.TextUtils;
Import Android.view.Menu;
Import Android.view.View;
Import Android.webkit.WebView;
Import android.webkit.WebViewClient;
Import Android.widget.EditText;
Import Android.widget.Toast;
public class Mainactivity extends activity {private EditText Etword;
Private WebView Wvresult;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Initviews ();
private void Initviews () {Etword = (edittext) Findviewbyid (R.id.etword);
Wvresult = (webview) Findviewbyid (R.id.wvsearchresult); Wvresult.setwebviewclient (New Webviewclient () {@Override public boolean shouldoverrideurlloading (WebView view, Stri
ng URL) {view.loadurl (URL);
return true;
}
}); @Override public boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.main, menu);
return true;
public void Searchword (view view) {String word = Etword.gettext (). toString ();
if (Textutils.isempty (word)) {Toast.maketext (this, "query content cannot be empty!", Toast.length_long). Show ();
else {final String strURL = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&vendor=&q=" + word;
Wvresult.loadurl (strURL);
}
}
}
More highlights you can refer to the topic to learn: "Android component WebView use case Summary"
The above is the entire content of this article, I hope to learn about Android software programming help, but also hope that we support the cloud habitat community.