错误仍然存​​在~“fullscreen_content_controls 无法解析或不是字段”

2024-04-25

我是一名 Android 开发新手,在尝试创建一个打开新布局的按钮时遇到了一些障碍。当我这样做时,我遇到了一些错误,无论我如何尝试,这些错误都不会消失。作为回应,我复制了大部分从原始结构更改的 xml 文件和 java 文件,并将它们添加到一个新项目中,以为所有错误都会消失。我真的需要一些帮助,我无法告诉你我被这个小错误困住了多久。我已附上主要 FullScreenActivity.java、activity_main.xml、Android 清单和错误消息。预先感谢各位的帮助,我真的很感激! C:

全屏活动.java ~

package sehej.android.doge;
import sehej.android.doge.util.SystemUiHider;
import sehej.android.doge.R;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;

public class FullscreenActivity extends Activity {
    /**
     * Whether or not the system UI should be auto-hidden after
     * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
     */
    private static final boolean AUTO_HIDE = true;

    /**
     * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
     * user interaction before hiding the system UI.
     */
    private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

    /**
     * If set, will toggle the system UI visibility upon interaction. Otherwise,
     * will show the system UI visibility upon interaction.
     */
    private static final boolean TOGGLE_ON_CLICK = true;

    /**
     * The flags to pass to {@link SystemUiHider#getInstance}.
     */
    private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;

    /**
     * The instance of the {@link SystemUiHider} for this activity.
     */
    private SystemUiHider mSystemUiHider;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

    ****    final View controlsView = findViewById(R.id.fullscreen_content_controls);
    ****    final View contentView = findViewById(R.id.fullscreen_content);

        // Set up an instance of SystemUiHider to control the system UI for
        // this activity.
        mSystemUiHider = SystemUiHider.getInstance(this, contentView,
                HIDER_FLAGS);
        mSystemUiHider.setup();
        mSystemUiHider
                .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
                    // Cached values.
                    int mControlsHeight;
                    int mShortAnimTime;

                    @Override
                    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
                    public void onVisibilityChange(boolean visible) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
                            // If the ViewPropertyAnimator API is available
                            // (Honeycomb MR2 and later), use it to animate the
                            // in-layout UI controls at the bottom of the
                            // screen.
                            if (mControlsHeight == 0) {
                                mControlsHeight = controlsView.getHeight();
                            }
                            if (mShortAnimTime == 0) {
                                mShortAnimTime = getResources().getInteger(
                                        android.R.integer.config_shortAnimTime);
                            }
                            controlsView
                                    .animate()
                                    .translationY(visible ? 0 : mControlsHeight)
                                    .setDuration(mShortAnimTime);
                        } else {
                            // If the ViewPropertyAnimator APIs aren't
                            // available, simply show or hide the in-layout UI
                            // controls.
                            controlsView.setVisibility(visible ? View.VISIBLE
                                    : View.GONE);
                        }

                        if (visible && AUTO_HIDE) {
                            // Schedule a hide().
                            delayedHide(AUTO_HIDE_DELAY_MILLIS);
                        }
                    }
                });

        // Set up the user interaction to manually show or hide the system UI.
        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TOGGLE_ON_CLICK) {
                    mSystemUiHider.toggle();
                } else {
                    mSystemUiHider.show();
                }
            }
        });
        };

        // Upon interacting with UI controls, delay any scheduled hide()
        // operations to prevent the jarring behavior of controls going away
        // while interacting with the UI.


    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

        // Trigger the initial hide() shortly after the activity has been
        // created, to briefly hint to the user that UI controls
        // are available.
        delayedHide(100);
    }

    /**
     * Touch listener to use for in-layout UI controls to delay hiding the
     * system UI. This is to prevent the jarring behavior of controls going away
     * while interacting with activity UI.
     */
    View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (AUTO_HIDE) {
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }
            return false;
        }
    };

    Handler mHideHandler = new Handler();
    Runnable mHideRunnable = new Runnable() {
        @Override
        public void run() {
            mSystemUiHider.hide();
        }
    };

    /**
     * Schedules a call to hide() in [delay] milliseconds, canceling any
     * previously scheduled calls.
     */
    private void delayedHide(int delayMillis) {
        mHideHandler.removeCallbacks(mHideRunnable);
        mHideHandler.postDelayed(mHideRunnable, delayMillis);
    }
}

活动_main.xml ~

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/grass"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:padding="20sp"
    app:textAlignment="center"
    tools:context=".MainActivity" >

    <requestFocus
        app:layout_width="wrap_content"
        app:layout_height="wrap_content" />

    <Button
        app:id="@+id/button2"
        style="@style/ButtonBar"
        app:layout_width="150dp"
        app:layout_height="wrap_content"
        app:layout_below="@+id/button1"
        app:layout_centerHorizontal="true"
        app:layout_marginTop="65dp"
        app:text="@string/button2"
        app:typeface="sans" />

    <Button
        app:id="@+id/button3"
        style="@style/ButtonBar"
        app:layout_width="150dp"
        app:layout_height="wrap_content"
        app:layout_alignLeft="@+id/button1"
        app:layout_below="@+id/button2"
        app:layout_marginTop="65dp"
        app:text="@string/button3"
        app:typeface="sans" />

    <Button
        app:id="@+id/button1"
        style="@style/ButtonBar"
        app:layout_width="150dp"
        app:layout_height="wrap_content"
        app:layout_alignLeft="@+id/button2"
        app:layout_below="@+id/textView1"
        app:layout_marginTop="22dp"
        app:onClick="whenClicked"
        app:text="@string/button1"
        app:typeface="sans" />

    <TextView
        app:id="@+id/textView1"
        app:layout_width="wrap_content"
        app:layout_height="wrap_content"
        app:layout_alignParentTop="true"
        app:layout_centerHorizontal="true"
        app:layout_marginTop="39dp"
        app:paddingBottom="30sp"
        app:text="@string/title"
        app:textColor="@color/blue"
        app:textSize="60sp"
        app:textStyle="bold"
        app:typeface="sans" />

安卓清单~

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="sehej.android.doge.FullscreenActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

问题视图中的错误消息~

fullscreen_content_controls 无法解析或者不是字段 FullscreenActivity.java /???/src/sehej/android/doge 第 54 行 Java 问题

fullscreen_content 无法解析或者不是字段 FullscreenActivity.java /???/src/sehej/android/doge 第 55 行 Java 问题

~~~~??? is the project/application name
~~~~I have marked the section that received the errors with '***'s

你还没有定义

fullscreen_content_controls
fullscreen_content

上面的id在你的activity_main.xml这就是为什么你会得到

fullscreen_content_controls 无法解析或者不是字段 FullscreenActivity.java 。

查看您的代码时,您还没有声明任何View与身份证

fullscreen_content_controls

fullscreen_content在你的activity_main.xml.

如果你想摆脱这个问题,你必须定义两个Views使用您在代码中提到的 id。

Edit

你通常会打电话setContentView(int)使用定义 UI 的布局资源,并使用findViewById(int)检索该 UI 中的小部件 因此,无论您在 Ui Xml 中声明了什么视图,您都可以获得这些视图。

就像你的情况一样,你已经定义了按钮,所以像

Button someButton = (Button) findViewById(R.id.button2);

现在可以为您工作,您可以在您的应用程序中使用这个小部件。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

错误仍然存​​在~“fullscreen_content_controls 无法解析或不是字段” 的相关文章

随机推荐