Android Uygulama Ders 2. İnternet Tarayıcısı yapma
Herkese merhaba proje konularından ders 2 yeni bir internet tarayıcısı yapmak oldu. Öncelikle webView hakkında bilginiz yoksa basit bir konu anlatımı için tıklayın.
Şimdi basit bir tarayıcı yapacağız. Öncelikle tasarımını halledelim.
Resim :
Kodlar:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | <RelativeLayout xmlns:android="//schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#E0E0D1" > <LinearLayout android:id="@+id/iki" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textViewURL" android:layout_width="50dp" android:layout_height="wrap_content" android:layout_weight="1" android:paddingLeft="13dp" android:textColor="#000" android:text="URL" /> <EditText android:id="@+id/URL" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" > </EditText> <Button android:id="@+id/Git" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Git" /> </LinearLayout> <WebView android:id="@+id/webV" android:layout_width="fill_parent" android:layout_height="850dp" android:layout_below="@id/iki" /> <LinearLayout android:id="@+id/bir" android:layout_width="match_parent" android:layout_height="wrap_content" android:weightSum="3" android:layout_below="@+id/webV" > <Button android:id="@+id/Geri" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Geri" /> <Button android:id="@+id/Anasayfa" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Anasayfa" /> <Button android:id="@+id/Ileri" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Ileri" /> </LinearLayout> </RelativeLayout> |
1 2 3 4 5 6 7 | Şimdi Java kodlarına başlayacağız : Resimleri: <img class="alignnone wp-image-1250" src="/wp-content/uploads/2015/07/2015-07-23_14h56_16.png" alt="2015-07-23_14h56_16" width="637" height="595" /><img class="alignnone wp-image-1251" src="/wp-content/uploads/2015/07/2015-07-23_14h56_26.png" alt="2015-07-23_14h56_26" width="639" height="635" /> <img class="alignnone wp-image-1252" src="/wp-content/uploads/2015/07/2015-07-23_14h56_36.png" alt="2015-07-23_14h56_36" width="758" height="606" /> <img class="alignnone wp-image-1253" src="/wp-content/uploads/2015/07/2015-07-23_14h56_45.png" alt="2015-07-23_14h56_45" width="634" height="479" /> Kodlar: |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | package com.example.myapplication; import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends ActionBarActivity { Button Geri,Ileri, Anasayfa, Git; WebView webV; EditText URL; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); webV = (WebView) findViewById(R.id.webV); webV.getSettings().setJavaScriptEnabled(true); webV.setWebViewClient(new MyWebViewClient()); webV.loadUrl("//www.google.com.tr"); URL = (EditText) findViewById(R.id.URL); Geri = (Button) findViewById(R.id.Geri); Ileri = (Button) findViewById(R.id.Ileri); Anasayfa = (Button) findViewById(R.id.Anasayfa); Git = (Button) findViewById(R.id.Git); Git.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (URL.getText().toString().length() > 10) { Toast.makeText( getApplicationContext(), URL.getText().toString() + " adresi yükleniyor...", Toast.LENGTH_SHORT).show(); if (InternetKontrol()) webV.loadUrl("//"+URL.getText().toString()); else BaglantiHatasiVer(); } else { Toast.makeText(getApplicationContext(), "Geçersiz Adres", Toast.LENGTH_SHORT).show(); } } }); Anasayfa.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (InternetKontrol()) webV.loadUrl("//www.google.com.tr"); else BaglantiHatasiVer(); } }); Geri.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (webV.canGoBack()) { webV.goBack(); } } }); Ileri.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (webV.canGoForward()) { webV.goForward(); } } }); } private class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } public void BaglantiHatasiVer() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( MainActivity.this); alertDialogBuilder.setTitle("Sunucu Hatası"); alertDialogBuilder.setMessage( "internet bağlantınızı kontrol edip tekrar deneyin") .setCancelable(true); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } public boolean InternetKontrol() { ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (manager.getActiveNetworkInfo() != null && manager.getActiveNetworkInfo().isAvailable() && manager.getActiveNetworkInfo().isConnected()) { return true; } else { return false; } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } |
1 | Ve son olarak Manifest dosyasına da 2 tane izin ekliyoruz. |
1 2 3 4 5 | <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> Uygulamanın çalıştırılması.. <a href="/wp-content/uploads/2015/07/2015-07-23_14h54_55.png"><img class="alignnone size-full wp-image-1249" src="/wp-content/uploads/2015/07/2015-07-23_14h54_55.png" alt="2015-07-23_14h54_55" width="892" height="1033" /></a> |
1 | Başarılar iyi günler.. |












merhabalar Ümit Bey
1-)activity main de ki < ve > diye kullandığınız kodlar nedir ?
2-)&& kodlarınız bende altı çizili olarak duruyor(hata veriyor) anlayamadım ne işe yarıyor?
3-)R.menu.menu_main, menu kodundaki menu yüde tanımadı çözemedim ?
1 ve 2 maddeyi çözdüm size mezaj yollarken fark ettim tag açıp kapamaymış lt ve gt 😀
Tama tüm hataları çözdüm 😀 başarılı bir şekilde çalışıyor
Ama sanırım sizin bir hatanız olabilir layoutlarla alakalı olarak belkide benim beceriksizliğim 😀 alt da geri anasayfa ileri butonları webview in altında kalıyor biraz ayar yapmak gerekiyor
4 RESİM 1 KELİME OYUNU YAPMAK İÇİN YARDIMCI OLUR MUSUNUZ ?