简体   繁体   中英

activity_splash cannot be resolved or its not a field in android app

The below are my activity_splash.xml layout and manifest.xml. when I'm using setContentView(R.layout.activity_splash) in java code, it is giving me error( activity_splash cannot be resolved or its not a field ). There is no reference to this xml file in R.java. Is there any problem with my code. I made only two changes after which this error came. Thats why I'm posting these 2 files here. What I'm trying to do is to load the URL in webview by showing splashscreen while the app is launched.

activity_splash.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"
android:background="#ffff0000 >

<ImageView
    android:id="@+id/imgLogo"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true"
    android:src="@drawable/nricabs"
    android:contentDescription="@string/app_name" />

<TextView
    android:id="@+id/url"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:textSize="22sp"
    android:layout_alignParentBottom="true"
    android:text="@string/url" />
</RelativeLayout>

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.browser"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@drawable/nricabs"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        //activity_splash.xml is used in seperate SplashScreen.java file

        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:name=".SplashScreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:name=".MainActivity"
        android:label="@string/app_name" >    
    </activity>
</application>

</manifest>

And also how to achieve the url loading in webview background while showing splashscreen. Is my approach correct?

try this,

your missing " (double quote) in following line.

android:background="#ffff0000"

following is your edited xml file

<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"
android:background="#ffff0000" >

<ImageView
    android:id="@+id/imgLogo"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true"
    android:src="@drawable/nricabs"
    android:contentDescription="@string/app_name" />

<TextView
    android:id="@+id/url"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:textSize="22sp"
    android:layout_alignParentBottom="true"
    android:text="@string/url" />
</RelativeLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM