Webview
2017. 8. 21. 02:51ㆍApplication Programming/Android
0) manifest.xml에 인터넷 사용 권한 추가
<uses-permission android:name="android.permission.INTERNET" />
1) WebView 객체 생성
2) findViewById로 위에서 생성한 객체와 뷰 연결
3) 객체.loadUrl("주소")
4) 객체.setWebViewClient(new VebViewClient())
public class MainActivity extends AppCompatActivityimplements NavigationView.OnNavigationItemSelectedListener {WebView mWebView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);setSupportActionBar(toolbar);FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);fab.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show();}});DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);drawer.setDrawerListener(toggle);toggle.syncState();NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);navigationView.setNavigationItemSelectedListener(this);//mWebView=(WebView)findViewById(R.id.webview1);mWebView.setBackgroundColor(0);mWebView.setHorizontalScrollBarEnabled(false);mWebView.setVerticalScrollBarEnabled(false);mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);mWebView.loadUrl("http://www.naver.com/");mWebView.setWebViewClient(new myWebViewClient());//}private class myWebViewClient extends WebViewClient {@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url){view.loadUrl(url);return true;}}
'Application Programming > Android' 카테고리의 다른 글
Google Place API 자동 검색 사용법 (0) | 2017.10.16 |
---|---|
구글맵 API V2 사용 시 com.google.android.gms.maps 포함 안되는 이유 (0) | 2017.09.20 |