(로고 및 아이콘 변경을 위한 app-manifests-androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloandroid">
//해당 프로젝트의 인터넷 접속을 위한 퍼미션
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:logo="@drawable/chiwawa"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="MainActivity"
android:label="간단 웹브라우저">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
///////////////////
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editUrl"
android:layout_weight="1"
android:singleLine="true" ></EditText>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnGo"
android:text="이동" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnBack"
android:text="이전" />
</LinearLayout>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView1"/>
</LinearLayout>
///////////////////////
package com.example.helloandroid;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
@SuppressWarnings("deprecation")
//java코드만을 이용해 액션바 구성하기
public class MainActivity extends AppCompatActivity{
EditText editUrl;
Button btnGo, btnBack;
WebView web;
@Override
protected void onCreate(Bundle SavedInstanceState) {
super.onCreate(SavedInstanceState);
setContentView(R.layout.activity_main);
editUrl=(EditText) findViewById(R.id.editUrl);
btnGo=(Button)findViewById(R.id.btnGo);
btnBack=(Button)findViewById(R.id.btnBack);
web=(WebView)findViewById(R.id.webView1);
web.setWebViewClient(new CookWebViewClinet());
//WebSettings 클래스를 이용, 줌 버튼 컨트롤이 화면에 보이게 한다
WebSettings webSet= web.getSettings();
webSet.setBuiltInZoomControls(true);
btnGo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//에디트 텍스트에 입력한 url웹페이지가 웹뷰(web)에 나오게 한다
web.loadUrl(editUrl.getText().toString());
}
});
btnBack.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
web.goBack(); //웹뷰의 이전 화면으로 돌아간다
}
});
}
//webviewclient의 상속을 받는 클래스의 정의
class CookWebViewClinet extends WebViewClient {
//shoudoverrideurlloading()의 상속을 한다.
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
}
}
//최종적으로, 프로젝트에 인터넷을 사용할 수 있는 퍼미션을 줘야 한다
//androidmanifest.xml에서 퍼미션을 지정할것
'애니리뷰' 카테고리의 다른 글
맵 공부 (0) | 2021.02.01 |
---|---|
실습 7-1)메뉴를 이용해 배경색을 바꾸기 (2) | 2020.08.14 |
액션바를 자바코드만으로 구현 (0) | 2020.08.13 |
직풀 6-3) (0) | 2020.08.13 |
직접풀어보기 6-2) (0) | 2020.08.13 |