간단한 브라우저 만들기
2019. 3. 19. 16:17ㆍAndriod
# *.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edtUrl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="URL을 입력하세요"
android:singleLine="true"/>
<Button
android:id="@+id/btnGo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="이동"/>
<Button
android:id="@+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="이전"/>
</LinearLayout>
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"/>
</LinearLayout>
# .java
package com.example.a0319_04;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
EditText edtUrl;
Button btnGo,btnBack;
WebView web;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtUrl = (EditText)findViewById(R.id.edtUrl);
btnGo = (Button)findViewById(R.id.btnGo);
btnBack = (Button)findViewById(R.id.btnBack);
web = (WebView)findViewById(R.id.webView1);
web.setWebViewClient(new WebViewClient());
WebSettings webset = web.getSettings();
webset.setBuiltInZoomControls(true);
btnGo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
web.loadUrl(edtUrl.getText().toString());
}
});// btnGo
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
web.goBack();
}
});//btnBack
}
class WebViewClient extends android.webkit.WebViewClient{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
}//Web
}
#### AndroidManifest.xml에서 다음 문구를 추가
'Andriod' 카테고리의 다른 글
예제: RadioButton,CheckBoxm,ImageView,Spinner (0) | 2019.04.08 |
---|---|
TapHost : 탭호스트 화면전환 (0) | 2019.03.19 |
Bar :ProgressBar,SeekBar,RatingBar (0) | 2019.03.19 |
ViewFlipper : 화면 전환 (0) | 2019.03.19 |
자동완성텍스트뷰,멀티자동완성테스트뷰 (0) | 2019.03.19 |