반응형
WebView 적용이 필요해서 작업중인데 Activity와 Fragment 방식이 달랐다.
공통
//AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
Activity 방식
//activity_main.xml
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
//MainActivity.java
public class MainActivity extends AppCompatActivity{
private WebView webview = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = findViewById(R.id.webView);
webview.setWebViewClient(new WebViewClient());
webview.setWebContentsDebuggingEnabled(true);
webview.loadUrl("https://www.naver.com");
}
}
Fragment 방식
//fragment_main.xml
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
//MainFragment.java
public class MainFragment extends Fragment {
private WebView webview = null;
private WebSettings mWebSettings = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main, container, false);
webview = view.findViewById(R.id.webView);
webview.setWebViewClient(new WebViewClient());
mWebSettings = webview.getSettings();
mWebSettings.setJavaScriptEnabled(true);
webview.loadUrl("https:/www.naver.com");
return view;
}
}
반응형
'공부 > App' 카테고리의 다른 글
[Flutter] 앱 아이콘 변경 (0) | 2024.09.24 |
---|---|
[Flutter] 앱 이름 변경 (안드로이드) (0) | 2024.09.24 |
[FLUTTER] SpringBoot gps정보 전송 (0) | 2024.09.20 |
안드로이드 Naver Map Api 사용하기 (0) | 2024.07.27 |
안드로이드 GPS 정보 가져오기 (0) | 2024.07.27 |