Full Edit since it apparently wasn't clear that this is indeed a programming question
On the Galaxy S4, the notification bar is transparent by default. When using the built-in "Bubbles" wallpaper this looks as follows for example:
Now I have developed my own live wallpaper. For sake of simplicity, I just fill the available canvas with 0xFFFF0000 for the screenshots, but normally it shows a different scene. On the Galaxy S4, my wallpaper does not show a transparent notification bar, but the default black one:
I noticed that sometimes my wallpaper shows a transparent bar also, here on the lockscreen. However, I was unable to reliably reproduce the behaviour.
My question is simply: is there any way to reliably enable the transparent notification bar from my wallpaper code or manifest? Actually, the unpredictable switching between transparent and black bar makes the user experience much worse than just with an always-black bar.
This is indeed possible on an unrooted S4:
public static boolean setTransparentNotificationBarTouchWiz(View view) {
try {
Field field = View.class.getDeclaredField("SYSTEM_UI_FLAG_TRANSPARENT_BACKGROUND");
Class<?> t = field.getType();
if (t == int.class) {
int value = field.getInt(null);
view.setSystemUiVisibility(value);
return true;
}
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
}
return false;
}
My thanks to Kevin # TeslaCoil for sharing this flag with me.
Sorry, unless you are making a custom ROM this isn't possible, unless you only want the status bar changed for your app.
This would require a heck of a lot of work.
First you will need to add Theme.NoTitleBar.Fullscreen to your manifest
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
>
Then once you have done that you need to create a standard layout which represents the status bar, this would mean that you have to add the time, and also receive all the notifications from other apps, I do not personally know how to do that but I'm sure there is a way.
If you really want to do this goodluck, you have a hard time ahead of you.
Related
I'm using Xamarin Forms to produce a TabbedPage consisting of more ContentPages. This is the part of code causing trouble:
public void launchMainDesign(object s, EventArgs e) {
MainPage = new TabbedPage {
Children = {
new ContentPage {
Title = "Login",
Content = pages.loginContent,
BackgroundImage = "bgmain.jpg"
},
new ContentPage {
Title = "Sign Up",
Content = pages.signUpContent,
BackgroundImage = "bgmain.jpg"
}
}
};
}
It seems absolutely fine. I have both the images in my Drawable directory, with the build action set to "AndroidResource".
Whenever the launchMainDesign() function is fired by pressing a button, the app crashes immediately, both in emulator and a build version of the app on a tablet. Unfortunately, I can't test on iOS and WP.
I even tried putting the whole inside part of the function in a try/catch block and print out the exception, but the app just crashes nevertheless.
I am desperately trying to solve this simple problem for about a week now. No one seems to be having exactly the same issue as me. Weirdest thing is, I have a different app where I use exactly the same method and it works just fine. Can the Android Theme be causing this (I'm using Holo, in the working app, there's no theme specified)? That seems to be the only difference.
I also don't think this is caused by RAM struggles, as the image is only about 700 kilobytes (1080x1920) - for this example, I've only used one image.
It could be a memory issue, because even do the size is not big depending on the device resolution it might be trying to scale the image to the device dimensions.
Try checking this README:
https://github.com/xamarin/customer-success/blob/master/samples/Xamarin.Forms/SliderView/README.md
Explains Xamarin.Forms Android Image Memory Management so could help you get around the issue you might be having.
so I am facing this problem for long time. I've got Nexus 4 and Nexus 7 both running Android 4.3, and i've got application with targetSdkVersion="11"("I use 11 because any target sdk below 11 doesn't support multitouch for me). And the problem is that 3-dot menu shows on Nexus 4 but doesnt show on Nexus 7. 3 dot menu button on nexus 7 works only if I put targetSdkVersion="8" but then multitouch doesnt work
Nexus 4:
Nexus 7 :
code :
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="11" />
screenshots :
nexus 7
nexus 4:
In case you are specifically wondering why the button is not being shown the following rules apply when Android determines if a legacy menu button is needed:
If target API version is less than 11 it is shown on all devices
If target version is 11, 12, or 13 (i.e. tablet-only Honeycomb) Android assumes that your app has been designed for tablets and won't show a legacy button on tablets, but will on phones
If target is 14 or above (ICS and above), Android assumes your app is designed for tablets and phones and so the legacy button isn't shown.
But like the other answers say, you shouldn't be using this menu button. If you don't want an entire ActionBar, another option would to have a three-dot button in your activity which shows a menu using PopupMenu.
You should not be using that menu anymore. From the Menus documentation:
On Android 3.0 and higher, items from the options menu are presented by the action bar as a combination of on-screen action items and overflow options. Beginning with Android 3.0, the Menu button is deprecated (some devices don't have one), so you should migrate toward using the action bar to provide access to actions and other options.
Use an ActionBar.
The correct solution is to use an ActionBar but there may be some hacks to get the overflow menu to appear.
Specifically, there's a hidden window flag FLAG_NEEDS_MENU_KEY you can access via reflection. Here's a code snippet (from this blog):
public static void addLegacyOverflowButton(Window window) {
if (window.peekDecorView() == null) {
throw new RuntimeException("Must call addLegacyOverflowButton() after setContentView()");
}
try {
window.addFlags(WindowManager.LayoutParams.class.getField("FLAG_NEEDS_MENU_KEY").getInt(null));
}
catch (NoSuchFieldException e) {
// Ignore since this field won't exist in most versions of Android
}
catch (IllegalAccessException e) {
Log.w(TAG, "Could not access FLAG_NEEDS_MENU_KEY in addLegacyOverflowButton()", e);
}
}
I tested this on a couple of Nexus devices and it works. Comments on the blog state that there are devices where it doesn't work. Use with caution. And use an ActionBar, really.
There's a simple way to force a menu option to stay in the menu overflow. If you're creating a menu with XML, you can force this using the "showAsAction" attribute.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_option"
android:showAsAction="never"
android:title="#string/option_name" />
</menu>
If you set "showAsAction" to "never", it will be forced to don't show on the ActionBar, so the option will remain on the menu overflow.
There's more info (like how to vinculate the XML menu file to an Activity) on the official Android documentation webpage: http://developer.android.com/guide/topics/resources/menu-resource.html
I wish this can be helpful!
I wouldnt always recommend using this, since its a hack which breaks the consistency of the phone, but if you want the "3 dots" menu, which is called the overflow menu you need to add this method
//Hack to display overflowMenu on devices with a menu button
private void getOverflowMenu() {
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}
}
And in your onCreate() call this method.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Activity);
getOverflowMenu();
}
How can I always show Android settings button on ActionBar? (4.0+)
I would like to show it even if the device has an hardware button for settings, so it would be same with devices with and without hardware buttons.
This is what I'm talking about: http://oi48.tinypic.com/2j104l0.jpg
There is one awful hack which generally have been answered on many questions. Call this from your onCreate():
private void getOverflowMenu() {
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}
}
It is highly suggested not to use this hack as sHasPermanentMenuKey field can change anytime. However this has been working for me and others uptil now. See
Android action bar not showing overflow
On a second note, the hardware button is present on the phone for a reason. Just showing the addition overflow menu might confuse your users. Ideally a user would be very much accustomed to using his/her personal phone. So, if the user's phone has a hardware button for overflow menu option, then it need not have the icon on the top of action bar. Having an addition button might confuse users due to difference in behavior in different apps.
Hope that helps.
Edit:
In short, its not recommended as sHasPermanentMenuKey field in the Android code can be changed anytime, which will break your app if not found.
Below is an image of the action bar on a Samsung Tab2 action bar running 4.0.3 android ICS
from left to right we have the "back, home, recent apps, screenshot, mini-app launcher, and system menu" buttons. Im certain i am not using the correct names for all these which is why i listed them from left to right along with the above image.
I know i can override the the functionality of "back" using:
#Override
public void onBackPressed() {
// Do something custom here
}
i also know that i can NOT override or remove the home button but i was wondering if i could remove or override the "recent apps", "take screen shot", and "mini app launcher"
would be nice if i could remove the back as well..
We just rolled out almost 100 GTab2s and have another 1,000 on order. This is something we've looked into extensively, especially in regards to screenshot and the minitab bloat. You can not remove the screenshot button, nor minitab, unless you root the device and modify the system image. (in short: you can't).
You could "remove" the home button by implementing your own launcher and getting rid of touchwiz.
FWIW, Samsung's B2B folks have been very helpful in supporting our efforts, even at our relatively small quantities. If you were building, say, a kiosk app around the GTab2, you might be able to get them to supply you with a less bloated image.
static public final String[] pkgs_GT_P3113_LH2 = new String[] { "com.kobobooks.samsung.android",
"com.netflix.mediaclient",
"com.nim.discovery",
"com.osp.app.signin",
"com.peel.app",
"com.samsung.mediahub",
"com.samsung.music",
"com.sec.android.app.gamehub",
"com.sec.android.app.minimode.res",
"com.sec.android.app.music",
"com.sec.android.app.readershub",
"com.sec.android.app.samsungapps",
"com.sec.android.app.sns3",
"com.sec.android.daemonapp.ap.yahoonews",
"com.sec.android.daemonapp.ap.yahoostock.stockclock",
"com.sec.android.widgetapp.ap.yahoonews",
"com.sec.android.widgetapp.at.yahoostock.stockclock",
"com.sec.android.widgetapp.minipaper",
"com.sec.chaton",
"com.sec.minimode.music",
"com.sec.pcw",
"com.tgrape.android.radar",
"com.zinio.samsung.android" };
I'm working in a launcher for Android ICS but I have a problem with tablets.
I can't hide the status bar. I have try it in Android 2.3.X and it's ok. The problem appears only with Android 4.0.
How can I hide it?
You can not get 100% true full screen in Android 4.0.
Use the following to dim the notification bar (aka. status bar, system bar)
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
And use this to hide it
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
And, if I guess right, you are trying to achieve a "kiosk mode". You can get a little help with an app named "surelock". This blocks all the "home" and "back" actions.
It is still not perfect but this may be the best we can achieve with Android ICS.
It is possible to hide the statusbar on a rooted android device. The program Hidebar does this by killing the systemui process. The program is open source, so you can read all about it in the source code.
See http://ppareit.github.com/HideBar/.
You cannot get rid of the system bar on tablets. You may be able to get rid of the navigation bar and status bar on phones. Please read the "Controls for system UI visibility" section of the Android 4.0 SDK release notes.
I know my answer comes a bit late, but after assembling info from various places, I came up with this, which works ONLY ON ROOTED DEVICES:
private void KillStatusBar()
{
Process proc = null;
String ProcID = "79"; //HONEYCOMB AND OLDER
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH){
ProcID = "42"; //ICS AND NEWER
}
try {
proc = Runtime
.getRuntime()
.exec(new String[] { "su", "-c",
"service call activity "+ProcID+" s16 com.android.systemui" });
} catch (IOException e) {
Log.w(TAG,"Failed to kill task bar (1).");
e.printStackTrace();
}
try {
proc.waitFor();
} catch (InterruptedException e) {
Log.w(TAG,"Failed to kill task bar (2).");
e.printStackTrace();
}
}
This should eliminate the bottom bar on any rooted device and turn it into "kiosk" mode.
To hide status bar and navigation bar in android 4.0, we should use code below:
LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
Building upon ppareit's answer.
You can not hide the navigation bar on most stock devices. However, there is a work around if you rooting the device is an option. Here are the steps for one solution:
Root device
Install and run Busybox (required for taking full advantage of rooted device)
Install HideBar from resource
In HideBar there is an option to run in 'Kiosk' mode, in which there is no way to re-display the navigation bar. Needless to say, you really need to be careful with this.