{"id":1210,"date":"2014-04-17T06:47:53","date_gmt":"2014-04-17T06:47:53","guid":{"rendered":"http:\/\/www.rezafaisal.net\/?p=1210"},"modified":"2014-04-17T07:03:58","modified_gmt":"2014-04-17T07:03:58","slug":"modifikasi-title-jendela-alert-pada-android-webview","status":"publish","type":"post","link":"https:\/\/www.rezafaisal.net\/?p=1210","title":{"rendered":"Modifikasi Title Jendela Alert pada Control WebView Android"},"content":{"rendered":"<p>Pada posting sebelumnya sudah dibahas tentang bagaimana agar aplikasi hybrid (gabungan aplikasi native dengan web, dengan menggunakan kontrol WebView) dapat terlihat se-native mungkin, dengan akal-akalan agar setiap ada perpindahan dari satu halaman ke halaman lain ditampilkan Progress Dialog, seperti yang bisa dibaca kembali pada link berikut <a title=\"http:\/\/www.rezafaisal.net\/?p=1041\" href=\"http:\/\/www.rezafaisal.net\/?p=1041\">http:\/\/www.rezafaisal.net\/?p=1041<\/a>. Dan hasilnya tidak mengecewakan.<\/p>\n<p><a href=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/04\/blog110.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"blog1\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"blog1\" src=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/04\/blog1_thumb2.jpg\" width=\"550\" height=\"302\" \/><\/a><\/p>\n<p>Bukan hanya itu, karena pada form tersebut di atas terdapat fitur untuk upload file, maka juga perlu dilakukan modifikasi agar WebView dapat melakukan hal tersebut. Selain agar memang aplikasi hybrid yang dibuat tetap \u201cterlihat\u201d native. Sehingga dapat terlihat seperti gambar di bawah ini.<\/p>\n<p><a href=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/04\/blog22.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"blog2\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"blog2\" src=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/04\/blog2_thumb1.jpg\" width=\"550\" height=\"303\" \/><\/a><\/p>\n<p>Cakep! Memang ide hebat dari sang ninja untuk hal ini :)<\/p>\n<p>Nah berikutnya adalah kasus berikut ini.<\/p>\n<p>Karena WebView adalah control yang \u201cisi\u201d-nya adalah halaman web, maka banyak prilaku yang bisa ditampilkan pada web browser juga dapat ditampilkan termasuk jendela Alert dari JavaScript. Secara default jendela Alert dapat ditampilkan pada WebView dengan tampilan seperti berikut :<\/p>\n<p><a href=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/04\/blog31.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"blog3\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"blog3\" src=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/04\/blog3_thumb1.jpg\" width=\"550\" height=\"303\" \/><\/a><\/p>\n<p>Nah pada title jendela Alert tersebut akan langsung ketahuan ternyata \u201cisi\u201d aplikasi ini adalah halaman web, oleh karena itu kita harus lakukan modifikasi sedikit agar title jendela tersebut tidak menunjukkan alamat web atau alamat IP seperti pada gambar tersebut. Yang perlu dilakukan adalah cukup menggunakan kode&#160; untuk melakukan override seperti berikut :<\/p>\n<div id=\"codeSnippetWrapper\" style=\"overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4\">\n<div id=\"codeSnippet\" style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white\">webView.setWebChromeClient(<span style=\"color: #0000ff\">new<\/span> WebChromeClient() {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">            <\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white\">    @Override<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">    <span style=\"color: #0000ff\">public<\/span> <span style=\"color: #0000ff\">boolean<\/span> onJsAlert(WebView view, String url, String message, <span style=\"color: #0000ff\">final<\/span> android.webkit.JsResult result)<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white\">    {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">        <span style=\"color: #0000ff\">new<\/span> AlertDialog.Builder(activity)<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white\">        .setTitle(<span style=\"color: #006080\">&quot;Petunjuk&quot;<\/span>)<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">        .setMessage(message)<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white\">        .setPositiveButton(android.R.string.ok, <span style=\"color: #0000ff\">new<\/span> AlertDialog.OnClickListener()<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">        {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white\">            @Override<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">            <span style=\"color: #0000ff\">public<\/span> <span style=\"color: #0000ff\">void<\/span> onClick(DialogInterface arg0, <span style=\"color: #0000ff\">int<\/span> arg1) {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white\">                result.confirm();<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">            }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white\">        }).setCancelable(false).create().show();<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">        <span style=\"color: #0000ff\">return<\/span> true;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white\">    }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4\">});<\/pre>\n<p><!--CRLF--><\/div>\n<\/div>\n<p>Hasilnya bisa dilihat pada gambar berikut :<\/p>\n<p><a href=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/04\/blog41.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"blog4\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px\" border=\"0\" alt=\"blog4\" src=\"http:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/04\/blog4_thumb1.jpg\" width=\"550\" height=\"304\" \/><\/a><\/p>\n<p>Gampang kan? Buat apa native kalau bisa hybrid #eh :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pada posting sebelumnya sudah dibahas tentang bagaimana agar aplikasi hybrid (gabungan aplikasi native dengan web, dengan menggunakan kontrol WebView) dapat terlihat se-native mungkin, dengan akal-akalan agar setiap ada perpindahan dari satu halaman ke halaman lain ditampilkan Progress Dialog, seperti yang&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1209,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6],"tags":[],"class_list":["post-1210","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-softwaredev"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.rezafaisal.net\/wp-content\/uploads\/2014\/04\/blog4_thumb1.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1sNAL-jw","_links":{"self":[{"href":"https:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/posts\/1210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rezafaisal.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1210"}],"version-history":[{"count":1,"href":"https:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/posts\/1210\/revisions"}],"predecessor-version":[{"id":1211,"href":"https:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/posts\/1210\/revisions\/1211"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rezafaisal.net\/index.php?rest_route=\/wp\/v2\/media\/1209"}],"wp:attachment":[{"href":"https:\/\/www.rezafaisal.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rezafaisal.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rezafaisal.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}