Styling FacebookActivity to avoid terrible progress bar - android

I just implemented logging in through Facebook using their SDK in conjunction with ParseFacebookUtilsV4.
In my manifest I had to declare a FacebookActivity that gets launched when I try to sign in, and that works great.
<activity android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:label="#string/app_name" />
This snippet comes from official docs so I didn't choose anything. What I found really weird is its styling. On my emulator (API 22) it has a ProgressBar that seems to be coming from the '90s! Is there a way to style it? I have tried changing the android:theme attribute, but with no success.
I thought of extending com.facebook.FacebookActivity, but after digging through source code I found out it inflates a com.facebook.LoginFragment, which is then responsible of the progress bar actually. Any ideas?

You can now set theme in your AndroidManifest.xml
commit src link
Usage:
AndroidManifest.xml
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<meta-data android:name="com.facebook.sdk.ApplicationName" android:value="#string/app_name"/>
<meta-data android:name="com.facebook.sdk.WebDialogTheme" android:value="#style/Theme.AppCompat.Light.NoActionBar"/>
This is valid for facebook-android-sdk v4.8.0+

First of all it's not progress bar, it's progress dialog. I don't know how make custom progress dialog with style.
So here is a solution changing default style(Theme_Translucent_NoTitleBar) with holo style(Theme.Holo.Light). For that we need to make changes in Facebook SDk.
1) Put below code in style.xml
<style name="NewDialogTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:background">#android:color/transparent</item>
</style>
2) And second thing that we need to change here in WebDialog.java inside com.facebook.widget package.
public static final int DEFAULT_THEME = R.style.NewDialogTheme;
Hope this helps you.

Only one method works for me:
FacebookSdk.setWebDialogTheme(android.R.style.Theme_Holo_Light_NoActionBar);
immediately after FacebookSdk.sdkInitialize

The android:theme you have set to your activity in your manifest is based on the original themes that were used in Android before Honeycomb. That's why your ProgressBar looks so old. You could try another theme like:
#android:style/Theme.Material.NoActionBar.TranslucentDecor
This is based on the new Material Design but of course this only works on Lollipop devices. Look into the AppCompat-Library for more Material Design styles that are compatible with older devices.

You can style whatever you want like this:
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:textViewStyle">#style/MyStyles.TextView</item>
<item name="android:buttonStyle">#style/MyStyles.Button</item>
<item name="android:progressBarStyle">#style/MyStyle.ProgressStyle</item>
<item name="android:indeterminateProgressStyle">#style/MyStyle.ProgressStyle</item>
<item name="android:actionBarStyle">#style/MyStyle.Toolbar</item>
</style>
Then
<style name="MyStyle.ProgressStyle" parent="android:Widget.Holo.Light.ProgressBar">
<item name="...">...</item>
</style>

When an Activity creates the View for a Dialog, it goes to the Activity's theme and looks up the theme specified by the android:alertDialogTheme attribute.
What you need to do is set that attribute to AppCompat's dialog theme (which for <v21 defaults to Theme.Holo):
In the theme that you apply to the Facebook Activity:
<style name="MyFacebookTheme" parent="#style/Theme.AppCompat.Light.NoActionBar">
...
<item name="android:alertDialogTheme">#style/Theme.AppCompat.Light.Dialog</item>
...
</style>

Related

App Crash at Launch (Material Theme issue)

I'm actually creating an app an I would like to use Material Theme Light.
So I put the line android:theme = "#android:style/Theme.Material.light"
on the manifest and no errors are displayed.
However when launching the app on my phone it crashes at launch although no errors are displayed in my xml/java sources.
I'm sure this line is the cause, because when I change the manifest to #style/AppTheme, it works and lauches.
It's driving me crazy, I need your help please.
It depends on your activity, What does your activity extend from? If it extends from AppCompatActivity you can't set material theme.
you should set AppTheme as your theme android:theme="#style/AppTheme"
and in style file, set AppCompat Theme as your parent:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Try this it will work click on values in resources than open styles.xml file and change this
with following
i was getting the same issue and it is due to the update in the material lib

UI freezes on removing white screen before splash

I am trying to remove white screen before splash so i followed solutions mentioned in these links
How To fix white screen on app Start up?
White screen before splashscreen
I tried almost every solution mentioned here
which includes changing activity theme to this
android:theme="#android:style/Theme.Translucent.NoTitleBar"
or adding this to my theme
<item name="android:windowDisablePreview">true</item>
but implementing any of this freezes the UI for a while on click of the App icon after that everything works fine as desired.
Has anyone succeeded to fix this lag. Any help will be appreciated.
create a custom theme like,
//splashTheme
//create in styles
<style name="splashTheme" parent="AppTheme">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and then apply the theme as follows,
//manifest file
<activity
android:name=".SplashActivity"
android:theme="#style/AppTheme.splashTheme"
android:windowSoftInputMode="adjustResize|stateHidden" />
try this.
following changes work for me on mac:
1.Goto android studio preferences.
2.In Build,Execution and Deployment select "Instant run".
3.disable-Enable instant run to hot swap code/resource changes on deploy.
4.apply changes,clean project and rebuild again.
Finally got my answer Splash Screen in Right Way. I do just following.
In values-->styles.xml I created splash screen background image
<style name="Splash" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">#drawable/splash</item>
</style>
For below api 19, in values-19->styles.xml I used
<style name="Splash" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
I removed setContentview() from SplashActivity and added style for splash screen in Manifest.xml file android:theme="#style/Splash"

Android - Hiding action bar in material theme in xml

I'm using a theme that inherits from "android:Theme.Material.Light" and am unable to find a way to hide the action bar from the xml style customizations. When using "Theme.AppCompat.Light" I was able to do it with something like this
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
How can I achieve a similar result with the material theme? I know you can hide it programmatically but not only is it inconvenient because you can't actually see the real layout on Android studio without having to run the app every time, but also, the action bar still appears for a second when you run the app, before getActionBar().hide() is run and it looks really unprofessional.
SOLUTION:
<style name="MyTheme" parent="android:Theme.Material.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
</style>
<style name="MyTheme" parent="android:Theme.Material.Light.NoActionBar">
<style name="NoActionBar" parent="_AppTheme">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowNoTitle">true</item>
</style>
and then apply the style to the Activity in your manifest as follow :
<activity
android:name=".youractivity"
android:theme="#style/NoActionBar" >
then if your java class extends the ActionBarActvity fix it to extend the Activity and also you had to change all the other Acivity to extend the Activity Class not the ActionBarActivity :)
i hope this will help you :)
Well I'm a bit late, but if someone is interested here is my solution.
I needed to inherit from a theme which has the action bar visible, so not using theme.NoActionBar.
Looking into the system theme here's what I found:
<style name="MainTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

Remove Android App Title Bar

I understand that these properties in the manifest:
android:theme="#android:style/Theme.NoTitleBar"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
can remove the title bar.
However, I constantly check the Graphical Layout when I am modifying my app. When I look at the Graphical Layout I still see the title bar. I want to remove the title bar in a way that I don't have to see it during the development of the game.
Simple way is to put this in your onCreate():
// Java
getSupportActionBar().hide();
// Kotlin
supportActionBar?.hide()
In the Design Tab, click on the AppTheme Button
Choose the option "AppCompat.Light.NoActionBar"
Click OK.
for Title Bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
for fullscreen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Place this after
super.onCreate(savedInstanceState);
but before
setContentView(R.layout.xml);
This worked for me.try this
I was able to do this for Android 2.1 devices and above using an App Compatibility library theme applied to the app element in the manifest:
<application
...
android:theme="#style/AppTheme" />
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.NoActionBar">
...
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>
</style>
Note: You will need to include the com.android.support:appcompat-v7library in your build.gradle file
There are two options I'd like to present:
Change the visibility of the SupportActionBar in JAVA code
Choose another Style in your project's style.xml
1:
Add getSupportActionBar().hide(); to your onCreate method.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
}
2:
Another option is to change the style of your Application. Check out the styles.xml in "app->res->values" and change
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Just use this
getSupportActionBar().hide();
If you use AppCompat v7, v21
getSupportActionBar().setDisplayShowTitleEnabled(false);
Use this to remove title from android app in your Androidmainfest.xml
android:theme="#android:style/Theme.NoTitleBar"
or you can use this in your activity
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
If you have import android.support.v7.app.ActionBarActivity; and your class extends ActionBarActivity then use this in your OnCreate:
android.support.v7.app.ActionBar AB=getSupportActionBar();
AB.hide();
In the graphical editor, make sure you have chosen your theme at the top.
It's obvious, but the App Theme selection in design is just for display a draft during layout edition, is not related to real app looking in cell phone.
Just change the manifest file (AndroidManifest.xml) is not enough because the style need to be predefined is styles.xml. Also is useless change the layout files.
All proposed solution in Java or Kotlin has failed for me. Some of them crash the app. And if one never (like me) uses the title bar in app, the static solution is cleaner.
For me the only solution that works in 2019 (Android Studio 3.4.1) is:
in styles.xml (under app/res/values) add the lines:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
After in AndroidManifest.xml (under app/manifests)
Replace
android:theme="#style/AppTheme">
by
android:theme="#style/AppTheme.NoActionBar">
Title bar in android is called Action bar. So if you want to remove it from any specific activity, go to AndroidManifest.xml and add the theme type. Such as android:theme="#style/Theme.AppCompat.Light.NoActionBar".
Example:
<activity
android:name=".SplashActivity"
android:noHistory="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In your res/values/styles.xml of modern Android Studio projects (2019/2020) you should be able to change the default parent theme
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
I went one step further and had it look like this
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowFullscreen">true</item>
</style>
This is based on the code generated from the Microsoft PWA builder https://www.pwabuilder.com/
in the graphical layout, you can choose the theme on the toolbar. (the one that looks like a star).
choose the NoTitleBar and have fun.
Just change the theme in the design view of your activity to NoActionBar like the one here
Use this Remove title and image from top.
Before:
setContentView(R.layout.actii);
Write this code:
requestWindowFeature(Window.FEATURE_NO_TITLE);
To open the Design window:
res->layouts->activity_manifest.xml
then click on the "Design" button, next to "Code" and "Split". On the TOP LEFT Corner.
Go to res/values/themes and change the third line to .NoActionBar like this in both.
<!-- Base application theme. -->
<style name="Theme.yourApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">

Why there is a white screen appears for 1sec when starting to run the apps in Android?

When I click the app icons and start to run the apps, it will appear a white screen for 1 sec.
I don't know why.
Is there any idea to clear this white screen and directly go to my activity?
The white/black screen is the window background image.
The window background is shown while e.g. your onCreate() runs and your layouts are being inflated. It can take some time especially if there's a lot of bitmaps that need to be read, decoded and scaled.
Changing the theme works because some themes have a non-default window background. For example, Theme.Wallpaper has a transparent background. There are other definitions there, too. Essentially what you want is:
<style name="YourTheme">
<item name="android:windowBackground">#null</item>
</style>
Programmatically you can achieve the same with
getWindow().setBackgroundDrawable(null);
at the top of activity onCreate().
(Old question but got bumped up by another answer and there wasn't a good answer.)
Settings. File>Settings>Build,Deployment>Instant Run Deselect all options shown there.
and add below line in your style.xml
<item name="android:windowDisablePreview">true</item>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowDisablePreview">true</item>
</style>
apply changes in AndroidMainfest.xml
<application
android:theme="#style/AppTheme">
After I change style.xml:
<resources>
<style name="AppTheme" parent="android:Theme.Wallpaper" />
</resources>
it works!!
Thanks all
Add the following in the manifest file of the corresponding activity
android:launchMode="standard"
and remove android:label="#string/app_name" from the corresponding activity ,this actually helped me
In your manifest.xml file remove the line android:theme="#style/AppTheme" for your app. and check it again
Use this tag in your manifest:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
In Styles add the following things
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">true</item>
Hope this will help you and its working for me

Categories

Resources