Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将我的网站转换为Android应用程序_Android_Hybrid Mobile App - Fatal编程技术网

如何将我的网站转换为Android应用程序

如何将我的网站转换为Android应用程序,android,hybrid-mobile-app,Android,Hybrid Mobile App,我创建了一个网站,现在我想把它转换成一个应用程序 我对Java或Android应用程序几乎一无所知。我在谷歌上搜索了一下,但我仍然不知道从哪里开始 我不是要求任何人为我编码。我只是想知道,我可以通过哪些步骤来实现我的目标。我应该从哪里开始 请告诉我,步骤是什么。也许,我在谷歌上用错误的关键词搜索 有没有开源或免费的项目可以帮助我做到这一点 使用Webview在Android应用程序中显示您的网站。基本用法 在应用程序中集成WebView只需两个步骤。首先,需要在xml布局中包含WebView元素

我创建了一个网站,现在我想把它转换成一个应用程序

我对Java或Android应用程序几乎一无所知。我在谷歌上搜索了一下,但我仍然不知道从哪里开始

我不是要求任何人为我编码。我只是想知道,我可以通过哪些步骤来实现我的目标。我应该从哪里开始

请告诉我,步骤是什么。也许,我在谷歌上用错误的关键词搜索


有没有开源或免费的项目可以帮助我做到这一点

使用Webview在Android应用程序中显示您的网站。基本用法

在应用程序中集成WebView只需两个步骤。首先,需要在xml布局中包含WebView元素

<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
尽管加载一个简单的url看起来很容易,但是定制WebView需要对WebView及其提供的方法有全面的了解。我们将从WebView提供的基本方法开始,稍后我们将构建一个简单的浏览器活动,它充当应用程序内浏览器,提供向后、向前和书签选项。我们将通过在Android Studio中启动一个简单的项目来逐一学习

2。创建新项目

  • 从文件在Android Studio中创建新项目⇒ 通过填写所需的详细信息创建新项目

  • 由于需要进行网络请求,我们需要在AndroidManifest.xml中添加INTERNET权限

  • AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="info.androidhive.webview" >
    
        <uses-permission android:name="android.permission.INTERNET"/>
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme.NoActionBar" >
            <activity android:name=".MainActivity" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    </manifest>
    
    四,。打开主活动(activity_main.xml和content_main.xml)和WebView元素的布局文件。除此之外,我还添加了CoordinatorLayout、工具栏和ProgressBar,它们将在加载网页时显示

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:fitsSystemWindows="true">
    
        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/detail_backdrop_height"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginEnd="64dp"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleTextAppearance="@android:color/transparent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">
    
                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">
    
                    <ImageView
                        android:id="@+id/backdrop"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:fitsSystemWindows="true"
                        android:scaleType="centerCrop"
                        app:layout_collapseMode="parallax" />
                </RelativeLayout>
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
            </android.support.design.widget.CollapsingToolbarLayout>
    
        </android.support.design.widget.AppBarLayout>
    
        <include layout="@layout/content_main" />
    
        <ProgressBar
            android:id="@+id/progressBar"
            style="@style/Widget.AppCompat.ProgressBar.Horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="-7dp"
            android:indeterminate="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    
    </android.support.design.widget.CoordinatorLayout>
    

    对于剩下的代码

    你可以使用混合应用程序(PhoneGap、ionic等),如果你已经用AngularJS或AngularJS完成了你的站点,你可以迁移到ionic、HTML、CSS、JS、PHP……是的,我想要混合应用程序。我想OP应该试一下这个答案。实施和检查这个过程只需要10到15分钟。是的,但这是我的问题,如何实施?我将尝试使用Phonegap,并通知您,如果我遇到任何问题,谢谢:)
    dependencies {
        ... 
        // glide
        compile 'com.github.bumptech.glide:glide:3.7.0'
    }
    
    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:fitsSystemWindows="true">
    
        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/detail_backdrop_height"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginEnd="64dp"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleTextAppearance="@android:color/transparent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">
    
                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">
    
                    <ImageView
                        android:id="@+id/backdrop"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:fitsSystemWindows="true"
                        android:scaleType="centerCrop"
                        app:layout_collapseMode="parallax" />
                </RelativeLayout>
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
            </android.support.design.widget.CollapsingToolbarLayout>
    
        </android.support.design.widget.AppBarLayout>
    
        <include layout="@layout/content_main" />
    
        <ProgressBar
            android:id="@+id/progressBar"
            style="@style/Widget.AppCompat.ProgressBar.Horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="-7dp"
            android:indeterminate="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    
    </android.support.design.widget.CoordinatorLayout>
    
    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fadeScrollbars="false"
        android:scrollbarFadeDuration="0"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
    
        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
    </android.support.v4.widget.NestedScrollView>
    
        package info.androidhive.webview;
    
    import android.content.Intent;
    import android.os.Bundle;
    import android.support.design.widget.AppBarLayout;
    import android.support.design.widget.CollapsingToolbarLayout;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.text.TextUtils;
    import android.view.MotionEvent;
    import android.view.View;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.ImageView;
    import android.widget.ProgressBar;
    
    import com.bumptech.glide.Glide;
    import com.bumptech.glide.load.engine.DiskCacheStrategy;
    
    
    public class MainActivity extends AppCompatActivity {
    
        private String postUrl = "http://api.androidhive.info/webview/index.html";
        private WebView webView;
        private ProgressBar progressBar;
        private ImageView imgHeader;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    
            webView = (WebView) findViewById(R.id.webView);
            progressBar = (ProgressBar) findViewById(R.id.progressBar);
            imgHeader = (ImageView) findViewById(R.id.backdrop);
    
            // initializing toolbar
            initCollapsingToolbar();
    
            webView.getSettings().setJavaScriptEnabled(true);
            webView.loadUrl(postUrl);
            webView.setHorizontalScrollBarEnabled(false);
        }
    
        /**
         * Initializing collapsing toolbar
         * Will show and hide the toolbar txtPostTitle on scroll
         */
        private void initCollapsingToolbar() {
            final CollapsingToolbarLayout collapsingToolbar =
                    (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
            collapsingToolbar.setTitle(" ");
            AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar);
            appBarLayout.setExpanded(true);
    
            // hiding & showing the txtPostTitle when toolbar expanded & collapsed
            appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
                boolean isShow = false;
                int scrollRange = -1;
    
                @Override
                public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                    if (scrollRange == -1) {
                        scrollRange = appBarLayout.getTotalScrollRange();
                    }
                    if (scrollRange + verticalOffset == 0) {
                        collapsingToolbar.setTitle("Web View");
                        isShow = true;
                    } else if (isShow) {
                        collapsingToolbar.setTitle(" ");
                        isShow = false;
                    }
                }
            });
    
            // loading toolbar header image
            Glide.with(getApplicationContext()).load("http://api.androidhive.info/webview/nougat.jpg")
                    .thumbnail(0.5f)
                    .crossFade()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(imgHeader);
        }
    }