如何使用Android Studio将网站转换为Android App

news/2024/5/14 0:07:35/文章来源:https://blog.csdn.net/culing2941/article/details/108617950

In this tutorial you will learn how to convert website to android app using Android Studio.

在本教程中,您将学习如何使用Android Studio将网站转换为android应用。

Before reading this tutorial I hope that you already have basic knowledge of Android App Development. Otherwise you won’t be able to understand anything.

在阅读本教程之前,我希望您已经具有Android App Development的基本知识。 否则,您将无法理解任何内容。

What I will do here is simply open the website in webview with a loading bar so that it will look like we are using an android app.

我在这里要做的就是简单地在Webview中使用加载栏打开网站,以便看起来我们正在使用android应用。

By using this method you can convert website or wordpress blog into android application. You can follow this link to see an example app that I have created using this process.

通过使用此方法,您可以将网站或wordpress博客转换为android应用程序。 您可以点击此链接查看我使用此过程创建的示例应用程序。

Note: Make sure the website for which you want to create app is responsive, otherwise the app will not look proper.

注意:请确保您要为其创建应用程序的网站具有响应能力,否则该应用程序将无法正常显示。

If you want to integrate admob and google analytics in your app then you can follow below tutorials.

如果您想将admob和Google Analytics(分析)集成到您的应用中,则可以按照以下教程进行操作。

Also Read: Android Google Analytics Integration Tutorial

另请参阅: Android Google Analytics(分析)集成教程

Also Read: Android AdMob Tutorial

另请参阅: Android AdMob教程

How to Convert Website to Android App Using Android Studio

如何将网站转换为Android App (How to Convert Website to Android App)

Create an android studio project with the website name.

使用网站名称创建一个android studio项目。

Add internet access permission to AndroidManifest.xml file.

将互联网访问权限添加到AndroidManifest.xml文件。

<uses-permission android:name="android.permission.INTERNET"/>

Add following code in activity_main.xml file. Here I have added a horizontal progress bar with a webview.

activity_main.xml文件中添加以下代码。 在这里,我添加了带有Webview的水平进度条。

activity_main.xml

activity_main.xml

<RelativeLayout 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"tools:context="com.myudaipurcity.MainActivity"><ProgressBarandroid:id="@+id/progressBar"style="?android:attr/progressBarStyleHorizontal"android:layout_width="fill_parent"android:layout_height="5dp"android:progressDrawable="@drawable/bg_progress_bar_webview" /><WebViewandroid:id="@+id/webView"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@+id/progressBar"/>
</RelativeLayout>

Create an xml file inside drawable folder and add following code in it. It is a custom background for progress bar. You can change the color by changing color code in res/values/color.xml file.

drawable文件夹中创建一个xml文件,并在其中添加以下代码。 这是进度条的自定义背景。 您可以通过更改res / values / color.xml文件中的颜色代码来更改颜色。

bg_progress_bar_webview.xml

bg_progress_bar_webview.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" ><itemandroid:id="@android:id/background"android:drawable="@color/colorAccent"/><item android:id="@android:id/secondaryProgress"><scaleandroid:drawable="@color/colorPrimary"android:scaleWidth="100%" /></item><item android:id="@android:id/progress"><scaleandroid:drawable="@color/colorPrimary"android:scaleWidth="100%" /></item></layer-list>

Add following code in MainActivity.java file. The code is self explanatory, I have added comments where ever required.

MainActivity.java文件中添加以下代码。 该代码是不言自明的,我在需要的地方添加了注释。

package com.thecrazyprogrammer;import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;public class MainActivity extends Activity {WebView webView;ProgressBar progressBar;String URL = "https://www.thecrazyprogrammer.com/";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);progressBar = (ProgressBar) findViewById(R.id.progressBar);webView = (WebView)findViewById(R.id.webView);webView.getSettings().setJavaScriptEnabled(true);//loading progressbarwebView.setWebChromeClient(new WebChromeClient() {public void onProgressChanged(WebView view, int progress){progressBar.setProgress(progress);if (progress == 100) {progressBar.setVisibility(View.GONE);} else {progressBar.setVisibility(View.VISIBLE);}}});webView.setWebViewClient(new WebViewClient() {@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url){view.loadUrl(url);return true;}});webView.loadUrl(URL);}//enabling back button to go to previous page@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (event.getAction() == KeyEvent.ACTION_DOWN) {switch (keyCode) {case KeyEvent.KEYCODE_BACK:if (webView.canGoBack()) {webView.goBack();} else {finish();}return true;}}return super.onKeyDown(keyCode, event);}
}

Finally save and run the project. Below is a screenshot how the app will look like.

最后保存并运行项目。 以下是该应用程序的屏幕截图。

How to Convert Website to Android App Using Android Studio (Screenshot)

Comment below if you have queries related to above tutorial for how to convert website to android application.

如果您对以上教程有疑问,请在下面评论,有关如何将网站转换为android应用程序。

翻译自: https://www.thecrazyprogrammer.com/2017/08/convert-website-android-app.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_734757.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

改善网站安全性的5种方法

Here you will know about some important website security tips. 在这里&#xff0c;您将了解一些重要的网站安全提示。 Owning a website is similar in a lot of ways to owning a brick-and-mortar store. It serves to promote and advertise your products and service…

手机访客获得访客手机号_每个新访客都希望从您的网站获得的7件事

手机访客获得访客手机号It is all but essential to have a website for your business in this day and age. As the first port of call for any newcomer to your brand, it needs to offer key information about your services and direct people on how to use them. Bey…

移动2018年年报 下载_2018年让网站具有移动响应能力至关重要的7个原因

移动2018年年报 下载The only thing more important than having a website is making it easily accessible to everyone. In 2018, people of all generations regularly use multiple devices. Once you’ve covered the website basics, it’s time to make sure that your…

seo传智播客2018_2018年最重要的4个SEO因素

seo传智播客2018SEO is always changing. It’s hard to keep up with the new rules and strategies for boosting your search engine ranking. In 2018, optimizing your website for Google and other search engines is no longer optional. With so much competition onl…

去过印度的人评价印度_印度5个最佳自由职业网站

去过印度的人评价印度Here you will get to know about some best freelancing sites in India. 在这里&#xff0c;您将了解印度一些最佳的自由职业者网站。 In the 21st century we do not really need to hard work in order to earn great, all we need is a great amount…

ux设计_为您的企业网站制作最佳UX设计的3条技巧

ux设计In the online world, the saying “never judge a book by its cover” does not apply. The visual things you post online will make or break your online presence. It’s no longer possible to satisfy a basic website visitor just by adding few elements on …

大数据开发要学哪种编程语言_编程语言技术:您应该使用哪一个来开发您的企业网站?

大数据开发要学哪种编程语言It is now easy for every business to have a website thanks to rapid advancements in web technologies. For a successful website strategy, you need to lay the right foundation which will be perfected by continuous maintenance and up…

如何将自定义JavaScript添加到您的WordPress网站?

When you want to change the theme of your site, one thing that needs to be done is to add custom JavaScript to it. However, there are other options available if you do not want to add it to your site. For instance, simply add the ‘Heat and Footer Script’…

创建类的三个步骤_如何通过5个简单的步骤创建企业网站

创建类的三个步骤Having the right business website can help any business alter their fortunes. If you are a small or big business owner, CEO, or entrepreneur, looking to grow your business, then it is important that you focus on your website. 拥有合适的企业…

网页和网站之间的区别

The difference between webpage and website is unanimously erred in terms of their functionalities, and often when anyone reads these two terms starting with “Web.” 网页和网站之间的区别在功能上是一致的&#xff0c;而且通常是当有人阅读以“ Web”开头的这两个…

ue4 加快移动_加快移动网站的9种方法

ue4 加快移动Website speed refers to how fast a site responds to requests from the Web. As I am about to highlight in this article, the speed with which a website load is very critical to both the users and owners. 网站速度是指网站响应Web请求的速度。 正如我…

有时候有些服务类的网站就是不走心啊

http://www.gb688.cn/BzptWeb/appmanager/eip/main?_nfpbtrue&_pageLabelportal_main_portal_page_4#wlp_portal_main_portal_page_4 请看&#xff1a; 文章来源&#xff1a;刘俊涛的博客 欢迎关注&#xff0c;有问题一起学习欢迎留言、评论转载于:https://www.cnblogs.co…

基于django的个人博客网站建立(七)

基于django的个人博客网站建立&#xff08;七&#xff09; 前言 网站效果可点击这里访问 这次在原来的基础上添加或修改一些小功能 具体内容 1.代码高亮 在原来的blog-details.html页面添加下面的代码&#xff1a; <link href"http://cdn.bootcss.com/highlight.js/9.1…

优酷网站服务器的带宽是多少,云服务器1M的带宽到底多大?90%的网站够用了

1M&#xff0c;作为云服务器最低的带宽配置&#xff0c;到底能承受多大的流量&#xff1f;在选配云服务器带宽的时候&#xff0c;看到带宽大小的时候&#xff0c;头疼病总是发作&#xff0c;带宽买小了&#xff0c;网站太卡&#xff0c;用户体验不好影响业务&#xff0c;带宽买…

使用码云或GitHub搭建简单的个人网站(补充hexo搭建博客)

视频链接&#xff1a;https://www.bilibili.com/video/av64294697 使用码云或GitHub搭建个人网站码云&#xff1a; 1、新建一个仓库 路径名会影响你的个人网站的网址&#xff08;自行修改&#xff09;&#xff0c;开源&#xff08;公开&#xff09;&#xff0c;其他默认…

bootstrap 分页_学习写个网站(5)Bootstrap学习2

吃了2天烧烤夜宵&#xff0c;还是得讲点自律。【正文】继续bootstrap&#xff0c;还是菜鸟教程。11. 分页就是还有种就是翻页&#xff0c;12. 标签class"label label-default">默认标签</span>label-primarylabel-success13. 警告就是那种可以取消的消息&am…

个人主页html代码_羡慕别人有自己的网站吗?这里有搭建免费个人主页的傻瓜式教程!...

想拥有一个免费的个人主页吗&#xff1f;在这里&#xff0c;你可以发布自己的博客、自由定制网站的主题&#xff0c;你可以拥有极好的创作体验&#xff0c;它可以成为你对外的一张“名片”&#xff0c;体现你的品味和兴趣&#xff0c;还有更重要的&#xff0c;它是免费的、可控…

springboot获取不到请求头_基于springBoot的国际化网站处理

为了在不同得语言环境下使用不同的语言提示&#xff0c;所以一般会在网站引入网站国际化处理。下面讲解一下springboot对这国际化的支持1.springboot进行国际化处理的类public class MessageSourceAutoConfiguration {Beanpublic MessageSource messageSource(MessageSourcePro…

大型游戏网站源码_自学Python才两天,就成功编写俄罗斯方块游戏,这难道不是天才?...

人们常说&#xff0c;python不适合做游戏&#xff0c;但我偏爱玩游戏&#xff0c;做不了大的&#xff0c;做个小的也行啊。于是&#xff0c;我在自己毫无基础的条件下&#xff0c;用两天时间学python基础理论&#xff0c;再用已有的俄罗斯方块游戏源码和源文件&#xff0c;在我…

如何使用Zend Framework、Smarty、Ajax创建一流的网站

如何使用Zend Framework、Smarty、Ajax创建一流的网站“读完本书后&#xff0c;我发现自己对Web开发和MVC模式的理解都已经今非昔比……强烈推荐此书&#xff01;”——Amazon.com“……一部极富启发性的PHP实战指导书&#xff0c;业界专家充分演示了如何使用Zend Framework、S…