Ciao,
ho un problema con l'action bar della mia "applicazione".
In pratica nell'activity in cui è presente un animazione Unity3d compare in maniera corretta l'action bar, ma i tasti non sono cliccabili, come si può vedere dai due screenshot seguenti :
Activity main in cui l'action bar funziona correttamente :
Activity contenente l'animazione di unity3d in cui l'actionbar non è cliccabile :
Video che forse fa capire un pò meglio il problema :
ecco il manifest della mia app :
1
2<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3package="com.rabidgremlin.tut.redcube"
4android:installLocation="auto"
5
6android:versionCode="1"
7android:versionName="1.0" >
8<!-- android:theme="@android:style/Theme.NoTitleBar"-->
9<supports-screens
10android:anyDensity="true"
11android:largeScreens="true"
12android:normalScreens="true"
13android:smallScreens="true"
14android:xlargeScreens="true" />
15
16<application
17android:icon="@drawable/app_icon"
18android:label="@string/app_name"
19android:theme="@android:style/Theme.Holo.Light" >
20
21<activity
22android:name="com.rabidgremlin.tut.redcube.UnityPl ayerNativeActivity"
23android:configChanges="mcc|mnc|locale|touchscreen| keyboard|keyboardHidden|navigation|orientation|scr eenLayout|uiMode|screenSize|smallestScreenSize|fon tScale"
24android:label="@string/app_name"
25
26android:screenOrientation="portrait" >
27<!--android:launchMode="singleTask"-->
28<meta-data
29android:name="unityplayer.UnityActivity"
30android:value="true" />
31<meta-data
32android:name="unityplayer.ForwardNativeEventsToDal vik"
33android:value="false" />
34</activity>
35<activity
36android:name="com.rabidgremlin.tut.redcube.MainAct ivity"
37android:label="@string/title_activity_main" >
38<intent-filter>
39<action android:name="android.intent.action.MAIN" />
40
41<category android:name="android.intent.category.LAUNCHER" />
42</intent-filter>
43</activity>
44</application>
45
46<uses-sdk
47android:minSdkVersion="17"
48android:targetSdkVersion="19" />
49
50<uses-feature android:glEsVersion="0x00020000" />
51
52</manifest>
53
54
e il file java della seconda activity contenente l'animazione di Unity3d
1101package com.rabidgremlin.tut.redcube;
2
3import android.app.ActionBar.LayoutParams;
4import android.app.NativeActivity;
5import android.content.res.Configuration;
6import android.graphics.PixelFormat;
7import android.os.Bundle;
8import android.view.KeyEvent;
9import android.view.Menu;
10import android.view.MenuItem;
11import android.view.MotionEvent;
12import android.view.View;
13import android.view.ViewGroup;
14import android.view.WindowManager;
15
16import com.unity3d.player.UnityPlayer;
17
18public class UnityPlayerNativeActivity extends NativeActivity
19{
20protected UnityPlayer mUnityPlayer;// don't change the name of this variable; referenced from native code
21
22// Setup activity layout
23protected void onCreate (Bundle savedInstanceState)
24{
25//requestWindowFeature(Window.FEATURE_NO_TITLE);
26super.onCreate(savedInstanceState);
27getWindow().takeSurface(null);
28//Theme_NoTitleBar_Fullscreen
29setTheme(android.R.style.Theme_Holo_Light);
30getWindow().setFormat(PixelFormat.RGB_565);
31
32mUnityPlayer = new UnityPlayer(this);
33/*if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
34getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
35WindowManager.LayoutParams.FLAG_FULLSCREEN);
36*/
37setContentView(mUnityPlayer);
38mUnityPlayer.requestFocus();
39}
40
41// Quit Unity
42protected void onDestroy ()
43{
44mUnityPlayer.quit();
45super.onDestroy();
46}
47
48// Pause Unity
49protected void onPause()
50{
51super.onPause();
52mUnityPlayer.pause();
53}
54
55
56// Resume Unity
57protected void onResume()
58{
59super.onResume();
60mUnityPlayer.resume();
61}
62
63// This ensures the layout will be correct.
64public void onConfigurationChanged(Configuration newConfig)
65{
66super.onConfigurationChanged(newConfig);
67mUnityPlayer.configurationChanged(newConfig);
68}
69
70// Notify Unity of the focus change.
71public void onWindowFocusChanged(boolean hasFocus)
72{
73super.onWindowFocusChanged(hasFocus);
74mUnityPlayer.windowFocusChanged(hasFocus);
75}
76// proviamo ad abilitare l'action bar :
7778public boolean onCreateOptionsMenu(Menu menu) {
79
80// Inflate the menu; this adds items to the action bar if it is present.
81getMenuInflater().inflate(R.menu.main, menu);
82return true;
83}
8485public boolean onOptionsItemSelected(MenuItem item) {
86// Handle action bar item clicks here. The action bar will
87// automatically handle clicks on the Home/Up button, so long
88// as you specify a parent activity in AndroidManifest.xml.
89int id = item.getItemId();
90if (id == R.id.action_settings) {
91return true;
92}
93return super.onOptionsItemSelected(item);
94}
95// For some reason the multiple keyevent type is not supported by the ndk.
96// Force event injection by overriding dispatchKeyEvent().
97public boolean dispatchKeyEvent(KeyEvent event)
98{
99if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
100return mUnityPlayer.injectEvent(event);
101return super.dispatchKeyEvent(event);
102}
103
104// Pass any events not handled by (unfocused) views straight to UnityPlayer
105public boolean onKeyUp(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); }
106public boolean onKeyDown(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); }
107public boolean onTouchEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); }
108/*API12*/ public boolean onGenericMotionEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); }
109}
110
Cosa potrebbe essere a non far funzionare l'action bar nella seconda activity ?