【问题标题】:Android Studio error after splash启动后的 Android Studio 错误
【发布时间】:2015-11-15 01:45:45
【问题描述】:

我已经按照教程进行了 4 次来制作启动画面,但在启动画面之后,应用程序出现错误并关闭。启动画面有一个停留 4 秒的图像,下一个屏幕有一个 webviewer,在查看器上方需要有标题栏。有什么想法吗?

Android Honey Comb 3.0 被设置为默认 Splash.java:

package nl.broodje.app.broodje;

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

/**
 * Created by Christiaan on 14-11-2015.
*/
public class Splash extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);
        Thread myThread = new Thread(){
            @Override
            public void run() {
                try {
                    sleep(3000);
                    Intent startMainScreen = new Intent(getApplicationContext(), MainActivity.class);
                    startActivity(startMainScreen);
                    finish();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        myThread.start();

    }
}

splash_screen.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/logo"
            android:id="@+id/imageView"
            android:layout_gravity="center_vertical" />
</LinearLayout>

content_main.xml:

            <?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"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                tools:context=".MainActivity"
                tools:showIn="@layout/activity_main">

                <WebView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/webView"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true" />
            </RelativeLayout>

activity_main.xml

            <?xml version="1.0" encoding="utf-8"?>
            <android.support.design.widget.CoordinatorLayout
                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" android:fitsSystemWindows="true"
                tools:context=".MainActivity">

                <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
                    android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

                    <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
                        android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
                        android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />

                </android.support.design.widget.AppBarLayout>

                <include layout="@layout/content_main" />

                <android.support.design.widget.FloatingActionButton android:id="@+id/fab"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"
                    android:src="@android:drawable/ic_dialog_email" />

            </android.support.design.widget.CoordinatorLayout>

MainActivity.java:

        package nl.broodjep.app.broodje;

        import android.os.Bundle;
        import android.support.design.widget.FloatingActionButton;
        import android.support.design.widget.Snackbar;
        import android.support.v7.app.AppCompatActivity;
        import android.support.v7.widget.Toolbar;
        import android.view.View;
        import android.view.Menu;
        import android.view.MenuItem;
        import android.webkit.WebView;

        public class MainActivity extends AppCompatActivity {

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

                String url = "http://broodje.nl/";
                WebView view=(WebView) this.findViewById(R.id.webView);
                view.getSettings() .setJavaScriptEnabled(true);
                view.loadUrl(url);

                Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
                setSupportActionBar(toolbar);

                FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
                fab.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                                .setAction("Action", null).show();
                    }
                });
            }

            @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);
            }
        }

AndroidManifest.xml

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/icoon"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Splash"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

【问题讨论】:

  • 请提供包含此类问题的堆栈跟踪。也就是说,您是否在清单中列出了 MainActivity,主题为 NoActionBar
  • @MikeM。清单是在上面添加的。我不能制作更多的代码块。所以我用空格做了。

标签: java android xml performance android-activity


【解决方案1】:

由于MainActivity extends AppCompatActivity,并且您正在设置自己的ActionBarMainActivity 需要有一个NoActionBar 主题,例如启动屏幕。

<activity android:name=".MainActivity"
    android:theme="@style/AppTheme.NoActionBar" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 2013-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多