Невозможно добавить заставку в приложение

Я новичок в студии Android. Я хочу узнать, как преобразовать веб-просмотр в приложение. Я написал код для того же:

activity_main.xml выглядит следующим образом:

<?xml version = "1.0" encoding = "utf-8"?>
    <RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
        xmlns:tools = "http://schemas.android.com/tools"
        android:id = "@+id/activity_main"
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"
        tools:context = "com.aarvansh.shoponline.shoponline.MainActivity">

        <WebView
            android:id = "@+id/webView"
            android:layout_width = "fill_parent"
            android:layout_height = "fill_parent"
            />
    </RelativeLayout>

AndroidMenifest.xml выглядит следующим образом:

<?xml version = "1.0" encoding = "utf-8"?>
<manifest xmlns:android = "http://schemas.android.com/apk/res/android"
    package = "com.aarvansh.shoponline.shoponline">

    <application
        android:allowBackup = "true"
        android:icon = "@mipmap/ic_launcher"
        android:label = "@string/app_name"
        android:roundIcon = "@mipmap/ic_launcher_round"
        android:supportsRtl = "true"
        android:theme = "@style/AppTheme">
        <activity android:name = ".MainActivity">
            <intent-filter>
                <action android:name = "android.intent.action.MAIN" />

                <category android:name = "android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name = "android.permission.INTERNET"/>
</manifest>

Main Activity.java - это:

package com.aarvansh.shoponline.shoponline;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

    private WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        webView = (WebView) findViewById(R.id.webView);
        webView.setWebViewClient(new myWebClient());
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://aarvanshinfotech.co.in/shop");

    }

    public class myWebClient extends WebViewClient
    {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            view.loadUrl(url);
            return true;

        }
    }

    @Override
    // This method is used to detect back button
    public void onBackPressed() {
        if (webView.canGoBack()) {
            webView.goBack();
        } else {
            // Let the system handle the back button
            super.onBackPressed();
        }
    }
}

Но когда я пытаюсь запустить этот apk, при запуске не загружается заставка. Я хочу загрузить заставку, на которой я хочу повернуть файл jpg при загрузке приложения

Где заставка?

Lucifer 15.03.2018 06:11

ваш код не имеет отношения к заставке!

Erfan 15.03.2018 06:12

вам нужно добавить еще одно действие i.s splash и сделать это действие как действие запуска, а затем перенаправить на MainActivity

Shubham Jain 15.03.2018 06:12

Не совсем понятно, что вы пробовали или почему вы ожидаете существования косой черты.

OneCricketeer 15.03.2018 06:20

В этом вам поможет: stackoverflow.com/questions/5486789/…

Faysal Ahmed 15.03.2018 06:45
0
5
48
2

Ответы 2

Вам нужно создать другое действие для экрана-заставки

Проверьте приведенный ниже код экрана-заставки

создайте новое пустое действие, чем просто используйте код ниже

настройте экран-заставку в соответствии с вашими требованиями

SAMPLE CODE

LAYOUT файл

<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
    xmlns:app = "http://schemas.android.com/apk/res-auto"
    xmlns:tools = "http://schemas.android.com/tools"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    tools:context = "com.example.SplashActivity">

    <ImageView
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_centerInParent = "true"
        android:src = "@drawable/logo" />

</RelativeLayout>

Код ACTVITY

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {


    private int SPLASH_TIME_OUT = 3000;    

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        getSupportActionBar().hide();    

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {   

                    Intent i = new Intent(SplashActivity.this, DashboardActivity.class);
                    startActivity(i);             
                    finish();                      

            }
        }, SPLASH_TIME_OUT);
    }


    @Override
    public void onBackPressed() {

    }
}

Добавьте это в свой проект Android, чтобы загрузить заставку. Вы можете изменить изображение логотипа в splashscreeen.xml в соответствии с вашими потребностями.

SplashScreenActivity.java

import java.util.Timer;
import java.util.TimerTask;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Window;

public class SplashScreenActivity extends Activity {

    // Set Duration of the Splash Screen
    long Delay = 8000;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Remove the Title Bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        // Get the view from splash_screen.xml
        setContentView(R.layout.splash_screen);

        // Create a Timer
        Timer RunSplash = new Timer();

        // Task to do when the timer ends
        TimerTask ShowSplash = new TimerTask() {
            @Override
            public void run() {
                // Close SplashScreenActivity.class
                finish();

                // Start MainActivity.class
                Intent myIntent = new Intent(SplashScreenActivity.this,
                        MainActivity.class);
                startActivity(myIntent);
            }
        };

        // Start the timer
        RunSplash.schedule(ShowSplash, Delay);
    }
}

splash_screen.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" >

    <ImageView
        android:id = "@+id/LogoImage"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_centerHorizontal = "true"
        android:layout_centerVertical = "true"
        android:src = "@drawable/logo" />

    <ProgressBar
        android:id = "@+id/ProgressBar"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_below = "@+id/LogoImage"
        android:layout_centerHorizontal = "true"
        android:layout_centerVertical = "true" >
    </ProgressBar>

</RelativeLayout>

AndroidManifest.xml В вашем файле манифеста Измените часть приложения, как показано ниже ...

<application
        android:icon = "@drawable/ic_launcher"
        android:label = "@string/app_name"
        android:theme = "@style/AppTheme" >
        <activity android:name = ".SplashScreenActivity" >
            <intent-filter>
                <action android:name = "android.intent.action.MAIN" />

                <category android:name = "android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name = ".MainActivity" >
        </activity>
    </application>

Другие вопросы по теме