The program interface is as follows!
1. layout file:
Copy codeThe Code is as follows: <AbsoluteLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: orientation = "vertical">
<EditText
Android: id = "@ + id/editText"
Android: layout_width = "150px"
Android: layout_height = "40px"
Android: layout_x = "5px"
Android: layout_y = "32px"
Android: textSize = "18sp"/>
<Button
Android: id = "@ + id/btnsearch"
Android: layout_width = "60px"
Android: layout_height = "40px"
Android: layout_x = "165px"
Android: layout_y = "35px"
Android: text = "query"/>
<Button
Android: id = "@ + id/btnclear"
Android: layout_width = "60px"
Android: layout_height = "40px"
Android: layout_x = "230px"
Android: layout_y = "35px"
Android: text = "clear"/>
<WebView
Android: id = "@ + id/reswebView"
Android: layout_width = "300px"
Android: layout_height = "330px"
Android: layout_x = "7px"
Android: layout_y = "90px"
Android: focusable = "false"/>
</AbsoluteLayout>
2. Modify MainActivity:
Copy codeThe Code is as follows: public class MainActivity extends Activity {
Private Button btnSearch;
Private Button btnClear;
Private EditText editText;
Private WebView reswebView;
Private void SetView (){
BtnSearch = (Button) findViewById (R. id. btnsearch );
BtnClear = (Button) findViewById (R. id. btnclear );
EditText = (EditText) findViewById (R. id. editText );
ReswebView = (WebView) findViewById (R. id. reswebView );
BtnSearch. setOnClickListener (new OnClickListener (){
@ Override
Public void onClick (View v ){
String strUri = editText. getText (). toString ();
StrUri = strUri. trim ();
If (strUri. length () = 0 ){
Toast. makeText (getApplicationContext (), "Enter the query character", 1). show ();
} Else {
String strURL = "http://dict.youdao.com/m/search? Keyfrom = dict. mindex & q = "+ strUri;
ReswebView. loadUrl (strURL );
}
}
});
BtnClear. setOnClickListener (new OnClickListener (){
@ Override
Public void onClick (View v ){
EditText. setText ("");
}
});
}
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
SetView ();
}
}
3. Add the network access permission to the configuration file:
<Uses-permission android: name = "android. permission. INTERNET"/>
Run the program!