I've exported an Unity app/game I have made to Android Studio. In Android Studio I made a layout and within it I have a framelayout. However, when I run the app the framelayout is completely black, why?
Here is my Java code:
public class UnityPlayerActivity extends Activity {
protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code
FrameLayout fl_forUnity;
Button bt_groen, bt_gul, bt_sort;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.RGBX_8888);
mUnityPlayer = new UnityPlayer(this);
if (mUnityPlayer.getSettings().getBoolean("hide_status_bar", true)) {
setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.main);
this.fl_forUnity = (FrameLayout) findViewById(R.id.fl_forUnity);
this.fl_forUnity.addView(mUnityPlayer.getView(),
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
this.bt_groen = (Button) findViewById(R.id.bt_groen);
this.bt_gul = (Button) findViewById(R.id.bt_gul);
this.bt_sort = (Button) findViewById(R.id.bt_sort);
this.bt_groen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
UnityPlayer.UnitySendMessage("Main Camera", "ReceiveRotDir", "G");
}
});
this.bt_gul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
UnityPlayer.UnitySendMessage("Main Camera", "ReceiveRotDir", "Y");
}
});
this.bt_sort.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
UnityPlayer.UnitySendMessage("Main Camera", "ReceiveRotDir", "B");
}
});
mUnityPlayer.requestFocus();
}
}
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:rowCount="3"
android:columnCount="10">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="400dip"
android:id="@+id/fl_forUnity"
android:background="#00FFFF"
android:layout_centerHorizontal="true">
</FrameLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Grøn"
android:id="@+id/bt_groen"
android:layout_column="4"
android:layout_row="2"
android:layout_alignTop="@+id/bt_sort"
android:layout_toRightOf="@+id/bt_sort"
android:layout_toEndOf="@+id/bt_sort"
android:layout_marginLeft="30dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gul"
android:id="@+id/bt_gul"
android:layout_column="9"
android:layout_row="2"
android:layout_alignTop="@+id/bt_sort"
android:layout_toLeftOf="@+id/bt_sort"
android:layout_toStartOf="@+id/bt_sort"
android:layout_marginRight="30dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sort"
android:id="@+id/bt_sort"
android:layout_below="@+id/fl_forUnity"
android:layout_centerHorizontal="true"
android:layout_margin="10dip" />
</RelativeLayout>