How to hide Android status bar in native game written with gomobile - android

How to hide Android status bar in native game written with gomobile?
I am experimenting with a simple native Android game written in pure Go using the gomobile tool. It should be able to use the full screen for rendering frames. However I could not find an API to hide the status bar from the native app.
Has anyone tackled this issue? If so, please share the directions.

Create a Empty Activity .
Go and find
android:theme="" on Activity XML Files
Set it to #style/Theme.AppCompat.NoActionBar
Pro Tip :
dont know other people but I always delete
Menu/Menu_Activity.Xml
That Contains Menu XML files !
Also Remove Menu.OnClick Codes Located on The Class of Your
Activity
Update :
Emm ... did you change :
public class Setup extends ActionBarActivity {
to
public class Setup extends Activity {
???

On the manifest add: theme: Theme.AppCompat.NoActionBar
For each activity page in which you dont want to show the status bar

This is how to disable the Android status bar in a native application written with gomobile:
Add this exact theme to AndroidManifest.xml:
<activity android:name="org.golang.app.GoNativeActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
</activity>

Related

Hide Android Navigation Bar in React Native

How can I hide the Android Navigation Bar in React Native?
I'm referring to the bar at the bottom of the screen that has the software back button and home button, not the component at the top of the page that comes with the Navigator Component.
This page on android.com explains how to do it for native developers. Can someone explain how to accomplish this via React Native apps? Thanks.
If you're looking to achieve this permanently you'll have to hide the Navbar when the app is created and when it comes back into focus.
To do so, add this in your MainActivity.java:
...
import android.os.Bundle;
import android.view.View;
public class MainActivity extends ReactActivity {
...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hideNavigationBar();
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
hideNavigationBar();
}
}
private void hideNavigationBar() {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
}
You may want to make it "immersive" so that the user can still access the navigation bar by pulling from the bottom of the screen.
To do so, add the View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY flag:
...
import android.os.Bundle;
import android.view.View;
public class MainActivity extends ReactActivity {
...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hideNavigationBar();
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
hideNavigationBar();
}
}
private void hideNavigationBar() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
You can find more options on the android documentation.
To hide the Android Navigation bar you can do that using react-native-navigation-bar-color it allows you to show or hide the navigation bar. You can see more in the documentation here. Note that it will not work on Expo as it requires you to link native code.
Installation is fairly straight forward:
npm install react-native-navigation-bar-color --save
Then you need to link the package (only for react-native <= 0.59.0):
react-native link react-native-navigation-bar-color
Once you have done that you can use it in the following way:
import {
HideNavigationBar,
ShowNavigationBar,
} from 'react-native-navigation-bar-color';
Then when you want to show the navigation bar you just use
ShowNavigationBar();
And to hide it you can use:
HideNavigationBar();
Building off of Martin Konicek's answer:
I went ahead and wrote the Package and Module you need here: https://gist.github.com/dhrrgn/16a8dfa7581a682627c6
You need to add it in your MainActivity.java file in the getPackages method, and send the package the ReactActivity object like this: new NavigationBarAndroidPackage(this)
Note: The code is untested, but it should work for you (you need to change the package on the first line). I just used the example code provided in the link you sent as an example. Modify to your needs.
I've created a package with navigation bar hide/show, color change and more.
react-native-system-navigation-bar
Install
yarn add react-native-system-navigation-bar
or
npm install react-native-system-navigation-bar
Links
https://www.npmjs.com/package/react-native-system-navigation-bar
https://github.com/kadiraydinli/react-native-system-navigation-bar
There is no built-in API to do this from JavaScript.
The good news is in React Native you can expose any native functionality to JavaScript, by writing a native module. See documentation.
This way you can provide a JS function like NavigationBarAndroid.hide() and make it call the API you linked to.
Use this: https://github.com/Anthonyzou/react-native-full-screen
usage:
import FullScreen from 'react-native-full-screen'
FullScreen.onFullScreen()
FullScreen.offFullScreen()
for expo builds:
expo install expo-navigation-bar
prevents content from jumping up with the navbar
NavigationBar.setPositionAsync("absolute");
hides the navbar
NavigationBar.setVisibilityAsync("hidden");
transparent background
NavigationBar.setBackgroundColorAsync("#ffffff00");
user can still swipe to show buttons
NavigationBar.setBehaviorAsync("inset-swipe");
I tried to wrap my screen in <TouchableWithoutFeedback > to be able to use onPress prop with NavigationBar.setVisibilityAsync("hidden"), but even without onPress the bottom navbar shows only for a brief second on swipe
Im in Android 9 and i did test the
import {HideNavigationBar} from 'react-native-navigation-bar-color';
but when Make Alt tabbing to another app, and returns then the nav bar appears again.
The best solution for me until moment is as said
Louis Zawadzki
Copying that on my mainactivity.java works fine, and always hide after changes.
I was stuck at the exact same point today. I found a medium article that got the job done. This question seems to be quite old however, some new readers might find this helpful.
https://medium.com/#mykl.ashton/how-to-hide-the-android-pie-navigation-bar-in-react-native-895e34c9e41
In this article, the writer has written native java methods to control the navigation bar and then used react native bridge to access the methods from react side.
It's a long article but has worked fantastically for me! hope this helps!

Can we change Normal Activities in android to Action Bar activities

I developed an app, but now I want to change all the Activities.
They all should have an ActionBar.
Can I directly convert my code by extending the existing Activities to get an ActionBar?
I would really appreciate any help.
-Agree with above answer. doing as per follow ..
public class YourActivity extends ActionBarActivity{
}
-And..You have to add this code into your manifest file
android:theme="#style/Theme.AppCompat"
-Under application tag
Definitely you can, like this, just you will need is Android Support Library (AppCompat lib)
public class YourActivity extends ActionBarActivity
And also do necessary changes regarding with ActionBar, you can get ActionBar object like ,
ActionBar mAction = getSupportActionBar();
mAction.setTitle("Your Title");

neokrees Navigation Drawer doesn't show up

As a newbie in Android programming I'm playing with some Material Design. So I wanted to implement a Navigation Drawer. After looking for libraries I decided to use #neokrees MaterialNavigationDrawer (https://github.com/neokree/MaterialNavigationDrawer). I added it into my build.gradle and followed the instructions from the wiki.
As a base I'm using a MainActivity which holds a toolbar and a fragment.
I created a custom style for the drawer and wrote a simple NavigationDrawer subclass.
import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
public class NavigationDrawer extends MaterialNavigationDrawer {
#Override
public void init(Bundle savedInstanceState) {
this.addSection(newSection("Section", new MainActivity.PlaceholderFragment()));
}
}
Then I added this to AndroidManifest.xml
<activity android:name=".NavigationDrawer"android:theme="#style/MyNavigationDrawerTheme" />
So everything compiles fine, the app starts up but nothing happens. So as first try I added a section to the drawer, relating to an activity. As I saw that the first item should be a fragment, I replaced it accordingly. Then I looked into the example app, but I don't get it to compile. Anyway, there is also no drawer-relevant code in the MainActivity.
So it's most probably a really dumb failure, but I have no idea anymore. So I would be thankful for any help.

Android application bar

Here is a pic of android applicationbar i like ( I mean the part where settings is written on, not sure if applicationbar is the right name :) )
http://oi50.tinypic.com/ehwwpc.jpg
Some apps i have downloaded also have the exact same bar so im guessing its a predefined theme but when i make a project (theme.holo) then my applicationbar is just totally black.
So my question is how do i get the same project bar?
Thank you!
Edit:
I found that all apps are opensoruce and i looked out settings apps manifest for android 4.0.4, same as mine.
Here it is: https://android.googlesource.com/platform/packages/apps/Settings/+/android-4.0.4_r2.1/AndroidManifest.xml
Whats strange is that it uses the same theme i do: android:theme="#android:style/Theme.Holo"
... but still the titlebar is different. There must be another attribute somewhere that defines the titlebar? Does anyone have an idea? :)
The title of the activity can be defined in the Manifest file, and it should be android:label property. For example:
<activity
android:name=".MainActivity"
android:label="#string/TitleBarText" />
TitleBarText is the android string resource that contains the name of the title.
If you wish to do it from code, you can just do the following in the onCreate method:
#Override
public void onCreate(Bundle savedInstanceState) {
setTitle("Title Bar Name");
setContentView(R.layout.activity_main);
}
To create a custom title bar, refer to: this and this

Unity3D Android Java Plugin : Button added on UnityPlayer Activity -> touch not working

I'm making a binding from Unity3D to a Java SDK. That Java SDK adds a View (RelativeLayout) to the current Activity (UnityPlayer.currentActivity) with an android.widget.Button in it.
The view is perfectly displayed but when the user touches/tap the button, the OnClickListener.onClick method of the button isn't called.
The view with the button is added using this code :
UnityPlayer.currentActivity.addContentView(view, params);
I think that Unity probably catches all user touch events. Is it possible to forward them so that the Button can fire the onClick ? Is there another way ?
Thanks in advance for your help.
Edit :
I tried to add in my Manifest for com.unity3d.player.UnityPlayerNativeActivity :
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
But no result so far :(
I did find a workaround while trying to solve this in one of my projects.
Solution:
ProxyActivity is the first activity that comes up. This opens Activity or NativeActivity, depending on the android version.
Make sure that the Activiy (not the NativeActivity) is shown. Code snippet to change in ProxyActivity:
Class activity = Class.forName(classNames[0]);
^^ Always force it to open the class which extends Activity and not the Native one.
Your assumption is correct, Unity is catching the input.
If you want to capture the input instead of Unity - you have to put your view into a separate window (Dialog), or create your own Activity. Both options are creating their own input loops hence overriding Unity loop.

Categories

Resources