I want to create game using Libgdx engine. It's create by default FULLSCREEN game without notification bar.
Can i create game with notification bar?
Since I am not (yet) allowed to comment I will make it an answer. Basically everything said by LiamJPeters helps, except you have set up the project recently from scratch with one of the newer libgdx nightlies, then there will also be a "res/values/styles.xml" which is referenced in the manifest.
I had to change two settings there (in addition to everything written by LiamJPeters) to make it finally show the notification bar and the window title:
<resources>
<style name="GdxTheme" parent="android:Theme">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
<item name="android:windowNoTitle">false</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowFullscreen">false</item>
</style>
</resources>
In the Android starter:
public class MainActivity extends AndroidApplication {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.hideStatusBar = false;
initialize(new MainClass(), cfg);
}
}
The important line here being cfg.hideStatusBar = false;
Hope that helps
EDIT
Ok so I've done a bit of research on the subject and it turns out it's pretty easy. I looked on the libgdx wiki page for adding admob ads. Follow all the steps except adding the ads!
Below is modified code for setting up a non-fullscreen android app:
public class MainActivity extends AndroidApplication {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout layout = new RelativeLayout(this);
layout.addView(initializeForView(new MainClass(), false));
setContentView(layout);
}
}
You can add all the layout parameters you want very easily by googleing "RelativeLayout layoutParams". Hope this helps. Please mark the question as answered.
I run into a confusion here and couldn't make it work for a while on Android Lollipop. I had to actually merge all the code provided here in the answers, to make my app show status bar.
So the final working code for me looks like this:
Java part - combining relative layout and hideStatusBar config (thanks to LiamJPeters)
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.hideStatusBar = false;
RelativeLayout layout = new RelativeLayout(this);
layout.addView(initializeForView(new MyAndroidApp(), config));
setContentView(layout);
}
And styles.xml part - windowFullscreen to false (thanks to Bernrd K.)
<resources>
<style name="GdxTheme" parent="android:Theme">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowFullscreen">false</item>
</style>
</resources>
Note: windowNoTitle has nothing to do with status bar itself. Depends what you need, but the xml above shows the status bar only, no titles.
Related
I'm using React Native for building my android application and I've followed this tutorial to set up my splash screen. Here is the result. My main problem is that the status bar color changes to black, I can't solve this by having <item name="colorPrimaryDark">#color/colorPrimaryDark</item> in my styles.xml file, and <color name="blue">#009CD7</color>, <color name="colorPrimaryDark">#009CD7</color> in my colors.xml file.
Bonus question: how to center the image without hardcoding a margin so that it stays in the center regardless of the device the app is running on?
Add colorPrimaryDark one more item in your current splash theme or create a new one.
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">#android:color/white</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:background">#drawable/background_splash</item>
<item name="colorPrimaryDark">#android:color/white</item>
</style>
Then use it as a second parameter while showing SplashScreen.
public class MainActivity extends ReactActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashTheme, true);
super.onCreate(savedInstanceState);
}
}
If you see an error something like that -> "int can not be boolean"
Just add third parameter to MainActivity.java
SplashScreen.show(this, R.style.SplashTheme, true);
Create a style definition for this in android/app/src/main/res/values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="SplashTheme" parent="SplashScreen_SplashTheme">
<item name="colorPrimaryDark">your_color</item>
</style>
</resources>
now you have change show method to include your custom style:
SplashScreen.show(this, R.style.SplashTheme);
you are donw now :)
If you wanna change the TaskBar color, just add the activity and the color that you desire in the output function.
fun setTaskBarColored(colored: Int,activity: Activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.window!!.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
activity.window!!.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
activity.window!!.statusBarColor = ContextCompat.getColor(activity, colored)
}
}
And also the same applies for the NavigationBar
fun setNavigationBarColored(colored: Int, activity: Activity){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.window!!.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
activity.window!!.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
activity.window!!.navigationBarColor = ContextCompat.getColor(activity, colored)
}
}
You can simply add this JSX code to the root of your app instead of editing any native files.
<StatusBar backgroundColor="blue" barStyle="light-content" />
Also in order to center your image, wrap it with a view and add the styling “{justifyContent: ‘center’, alignItems: ‘center’}”. If that doesn’t work then add this style directly to your image component “alignSelf: ‘center’”
Is it possible if my theme values are downloadable from server then my mobile theme will change according to what I specify from it?
Example if I have columns [colorPrimary] and [colorAccent] from server then after downloading values, my app theme colors will change accordingly.
This is my current theme.
<style name="Base.Theme.Design" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#013034</item>
<item name="colorPrimaryDark">#013034</item>
<item name="colorAccent">#1490a0</item>
<item name="android:textColorHint">#9e9e9e</item>
</style>
Note: For all downvotes, please leave comment for improvement of this post. Thanks.
You can use Firebase remote config to apply that, for example if you have multiple theme options for your app like "Base.Theme.Design_A" and "Base.Theme.Design_B" which are already built-in your app. You can switch between and apply one of these themes by checking a remote property in Firebase remote config. Also you can change old value and fetch the remote values and activate them (not with style file)
<defaultsMap>
<entry>
<!-- color entries -->
<entry>
<key>colorPrimary</key>
<value>#013034</value>
</entry>
<entry>
<key>colorPrimaryDark</key>
<value>#013034</value>
</entry>
To change your app's colour dynamically, for elaborate implementations refer to this
There is a way to change your App's theme dynamically.
You need put two the themes in your styles.xml in advance, like this:
<style name="AppThemeA" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#aba424</item>
<item name="colorPrimaryDark">#9f2020</item>
<item name="colorAccent">#2a6c29</item>
</style>
<style name="AppThemeB" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#706464</item>
<item name="colorPrimaryDark">#831444</item>
<item name="colorAccent">#183150</item>
</style>
And use one of them in your codes.
For example, there is button in your MainActivity, if you click it, your theme will change to AppThemeA, so you need do this in your MainActivity's OnCreate:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
if ("A".Equals(Intent.GetStringExtra("Theme")))
{
SetTheme(Resource.Style.AppThemeA);
}
else if("B".Equals(Intent.GetStringExtra("Theme"))) {
SetTheme(Resource.Style.AppThemeB);
}
SetContentView(Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.bt);
button.Click += (sender, e) => {
Intent intent= new Intent(this, typeof(MainActivity));
intent.PutExtra("Theme","A");
StartActivity(intent);
Finish();
};
}
There are some questions about Fullscreen but in my case, I'm using one java class with (AbsRuntimePermission extends AppCompatActivity) and the (MainActivity extends AbsRuntimePermission)
My problem is: the Fullscreen mode is working just in the Samsung phone.
By the way, the Home button is my problem, the title is already hidden.
In my MainActivity I'm using this windows code:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestAppPermissions(new String[]{android.Manifest.permission.RECORD_AUDIO, android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
android.Manifest.permission.INTERNET, Manifest.permission.READ_EXTERNAL_STORAGE}, R.string.msg, REQUEST_PERMISSION);
In my Styles I'm using the .AppCompat.NoActionBar.
<style name="PlayerTheme" parent="Theme.AppCompat.NoActionBar">
Following another questions about Fullscreen, I tryed to use this code in my styles
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="#style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
and then change the manifest for theme .AppCompat.Light.NoActionBar.FullScreen But it is not working.
Are there any permission that I need to use when I have RuntimePermission?
solved: i have check this code it works on android version 4.0.4 api(15) and some above versions
after content view ADD this this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
chnage your style into
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
if your using api level 19 or above than use Immersive Full-Screen Mode override this function it will works fine
ex:
#Override
public void onWindowFocusChanged(boolean hasFocus){
super.onWindowFocusChanged(hasFocus);
View decorView = getWindow().getDecorView();
if(hasFocus){
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
}
hope answered the question if its useful than vote up
Getting a full screen (no title bar/statusbar/navbar) when your MainActivity is inheriting from FormsApplicationActivity isn't much of a problem.
But then you can't theme it etc.
The current VS solution templates have you inheriting from FormsAppCompatActivity which you can theme. But then the status bar comes back.
It just shouldn't be days of looking at out-of-date how-to pages and mountains of trial and error with countless permutations of these different 'tricks' just to get a full-page app. I have hit every google search, every stack overflow, other questions here with examples that once worked in 2011 and so on. But I can't find or figure out how to make it work today, 2017 on a modern VS solution.
Maybe I've just tried so many different ways I've gotten lost or have multiple different ways conflicting with each other, but can anyone show me how on a basic "Welcome To Xamarin" kind of app how to get it go full screen? I've gotten so close, but not quite there. The best I can do is to have no content in the status bar, but the bar itself is still there. I can' t believe something as common place as wanting a full-screen app is kicking my arse, but it is.
Get rid of the Navigation bar
public partial class App : Application
{
public App()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
MainPage = new NavigationPage(new RpxOne.MainPage());
}
MainActivity.cs
Set the theme in the Activity attributes
Set the windows flags
(Clearly lot of various efforts and permutations to get this to work)
[Activity(Label = "RpxOne",
Icon = "#drawable/icon",
Theme = "#style/FullScreen",
MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize |
ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
WindowManagerFlags _originalFlags;
protected override void OnCreate(Bundle bundle)
{
SupportRequestWindowFeature((int)WindowFeatures.NoTitle);
//RequestWindowFeature(WindowFeatures.NoTitle);
//TabLayoutResource = Resource.Layout.Tabbar;
//ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
//if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
//{
// // Kill status bar underlay added by FormsAppCompatActivity
// // Must be done before calling FormsAppCompatActivity.OnCreate
// this.Window.DecorView.SystemUiVisibility = StatusBarVisibility.Hidden;
// ActionBar?.Hide();
//}
//else
//{
// this.Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
// SupportActionBar?.Hide();
//}
//global::Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never);
//Window.ClearFlags(WindowManagerFlags.ForceNotFullscreen);
//Window.ClearFlags(WindowManagerFlags.Fullscreen);
//Window.AddFlags(WindowManagerFlags.Fullscreen |
// WindowManagerFlags.TurnScreenOn |
// WindowManagerFlags.KeepScreenOn);
this.Window.ClearFlags(WindowManagerFlags.Fullscreen);
this.Window.AddFlags(WindowManagerFlags.Fullscreen); // hide the status bar
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
And then the theme itself
<style name="FullScreen" parent="#style/Theme.AppCompat.Light.NoActionBar">
<!--<item name="windowNoTitle">true</item>-->
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<!--<item name="android:windowContentOverlay">#null</item>
<item name="android:actionBarSize">0dp</item>-->
<!--<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
--><!-- No backgrounds, titles or window float --><!--
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">false</item>
--><!--<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>-->
</style>
Original post on Xamarin Forums
https://forums.xamarin.com/discussion/90145/how-to-get-a-full-screen-app-in-todays-xf-193-appcompat-environment-it-shouldnt-be-this-hard
No replies - I can't believe this is such a mystery.
Code for hiding title bar and action bar actually works, the action bar you see is a view created by Xamarin.Forms view renderer. By checking the Hierarchy Viewer of DDMS, you can see this view:
Since we cannot modify the source code of xamarin forms, here is a workaround to solve this issue. Create a style like so:
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="#style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<!--colorPrimaryDark is used for the status bar-->
<item name="colorPrimaryDark">#fff9f9f9</item>
</style>
And in MainActivity:
[Activity(Label = "FormsIssue6", Icon = "#drawable/icon", Theme = "#style/Theme.AppCompat.Light.NoActionBar.FullScreen", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
//ToolbarResource = Resource.Layout.Toolbar;
//RequestWindowFeature(WindowFeatures.NoTitle);
//Window.AddFlags(WindowManagerFlags.Fullscreen | WindowManagerFlags.TurnScreenOn);
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
This is only a workaround, the view there for action bar will still occupy the space in the layout.
And the reason why I used color #fff9f9f9, I only check the souce code, the <drawable name="input_method_fullscreen_background"> item seems to be right by my side, I didn't find the source code for Xamarin.Forms, you can give a try.
I have a dialog-style activity that appears over my main activity in an Android application. How can I get the background to be translucent? Not transparent, but translucent - say 70% opaque. I've tried applying this theme to the activity:
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
and several variations on this but still the dialog activity appears 100% opaque. Also, the layout xml of the activity itself (and elements displayed on it), specify a background of "#70000000".
For totally transparent dialog you can use this :
Step 1> Create a colors.xml file in the ‘values’ folder under ‘res’ and add the following line..
<drawable name="transparent">#00000000</drawable>
Step 2> Create a styles.xml file in the ‘values’ folder under ‘res’ and the following lines…
<style name="Transparent">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">
#android:style/Animation.Translucent
</item>
<item name="android:windowBackground">#drawable/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorForeground">#fff</item>
</style>
(I guess the tags and attributes are self explanatory…)
Step 3> Actually, that's it……………………
Let’s add this to a dialog…..
Step 4> Create a class with the following lines……
public class DialogBox extends Dialog {
public DialogBox(Context context, int theme) {
super(context, theme);
setContentView(R.layout.dialog);
okButton = (Button) findViewById(R.id.dialog_OkButton);
setListeners();
}
}
(Make sure you create a layout for the dialog)
Step 5> Next create an activity class as follows….
public class T_Temp extends Activity {
private DialogBox dialog;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dialog = new DialogBox(this, R.style.Transparent);
dialog.show();
}
}
or you can use this to make dialog attractive to add blur effect ....
Just check this out: there is near about 30% transparency...
dialog = new AlertDialog.Builder(WordCube.this)
.setTitle(WordCube.this.getResources().getString(R.string.app_name))
.setMessage(s)
.setIcon(R.drawable.logo)
.setPositiveButton(R.string.btn_close, null)
.show();
Below shows the code needed to add blur and remove dimming of the background (as I think the blur looks nicer when the background is well lit).
view plaincopy to clipboardprint?
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.dimAmount=0.0f;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);