我是一名 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