我試圖將示例活動添加到現有項目。該項目使用Gradle編譯良好,但在將活動聲明添加到清單 後,編譯後的清單在http://schemas.android.com/apk/res/android處爲紅色,並顯示爲「URI未註冊」的浮動消息。添加新活動後'URI未註冊'
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.YouTuber" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="@string/action_bar_demo_name"
android:name=".ActionBarDemoActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="sensorLandscape">
<meta-data android:name="@string/minVersion" android:value="11"/>
<meta-data android:name="@string/isLaunchableActivity" android:value="true"/>
</activity>
</application>
添加的活性actionBarDemoActivity從YouTube API示例項目採取。
/*
* Copyright 2012 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.YouTuber;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.KalromSystems.YouTuber.YouTuber.DeveloperKey;
import com.KalromSystems.YouTuber.YouTuber.YouTubeFailureRecoveryActivity;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerFragment;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
/**
* A sample showing how to use the ActionBar as an overlay when the video is playing in fullscreen.
*
* The ActionBar is the only view allowed to overlay the player, so it is a useful place to put
* custom application controls when the video is in fullscreen. The ActionBar can not change back
* and forth between normal mode and overlay mode, so to make sure our application's content
* is not covered by the ActionBar we want to pad our root view when we are not in fullscreen.
*/
@TargetApi(11)
public class ActionBarDemoActivity extends YouTubeFailureRecoveryActivity implements
YouTubePlayer.OnFullscreenListener {
private ActionBarPaddedFrameLayout viewContainer;
private YouTubePlayerFragment playerFragment;
private View tutorialTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.action_bar_demo);
viewContainer = (ActionBarPaddedFrameLayout) findViewById(R.id.view_container);
playerFragment =
(YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.player_fragment);
tutorialTextView = findViewById(R.id.tutorial_text);
playerFragment.initialize(DeveloperKey.DEVELOPER_KEY, this);
viewContainer.setActionBar(getActionBar());
// Action bar background is transparent by default.
getActionBar().setBackgroundDrawable(new ColorDrawable(0xAA000000));
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
player.setOnFullscreenListener(this);
if (!wasRestored) {
player.cueVideo("9c6W4CCU9M4");
}
}
@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.player_fragment);
}
@Override
public void onFullscreen(boolean fullscreen) {
viewContainer.setEnablePadding(!fullscreen);
ViewGroup.LayoutParams playerParams = playerFragment.getView().getLayoutParams();
if (fullscreen) {
tutorialTextView.setVisibility(View.GONE);
playerParams.width = MATCH_PARENT;
playerParams.height = MATCH_PARENT;
} else {
tutorialTextView.setVisibility(View.VISIBLE);
playerParams.width = 0;
playerParams.height = WRAP_CONTENT;
}
}
/**
* This is a FrameLayout which adds top-padding equal to the height of the ActionBar unless
* disabled by {@link #setEnablePadding(boolean)}.
*/
public static final class ActionBarPaddedFrameLayout extends FrameLayout {
private ActionBar actionBar;
private boolean paddingEnabled;
public ActionBarPaddedFrameLayout(Context context) {
this(context, null);
}
public ActionBarPaddedFrameLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ActionBarPaddedFrameLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
paddingEnabled = true;
}
public void setActionBar(ActionBar actionBar) {
this.actionBar = actionBar;
requestLayout();
}
public void setEnablePadding(boolean enable) {
paddingEnabled = enable;
requestLayout();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int topPadding =
paddingEnabled && actionBar != null && actionBar.isShowing() ? actionBar.getHeight() : 0;
setPadding(0, topPadding, 0, 0);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
控制檯誤差約爲MINVERSION: 錯誤:(33 31)沒有資源發現,給定名稱(在 '名稱',值爲 '@字符串/ MINVERSION')相匹配。
雖然看起來只是一個症狀。
見你也可以張貼活動和錯誤機器人工作室告訴你http://schemas.android.com/apk/res/android – litelite
添加活動代碼。 – mik
你的'strings.xml'中有一個名爲'minVersion'的字符串嗎? – litelite