Or kind of.
I've got an activity with a fragment container. Each Fragments layout has no background itself. I've already tried to set background to transparent - no effect.
Also I'm using FragNav library to handle fragment transactions.
The thing is - widnows background shows correctly in the editor xml preview.
Style:
<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#drawable/ng_window_background</item>
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
</style>
Drawable "ng_windows_background" is just a shape with solid color. Colors HEX is #FDA23.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#color/colorAccent"/>
</shape>
XML preview example: The background color is orange.
Screenshot from device As you can see, the background color is gray.
What I've already tried:
Changing fragment's layout background (android:background) color. Yes, it works, but it causes overdraw effect, which I am trying to avoid by using android:windowBackground attribute.
Using android:colorBackground attribute, due to material components recommendations. No effect.
Changing app's theme programmatically and in manifest. No effect.
Changing Theme.MaterialComponents.NoActionBar to AppCompat. No effect + I can't use AppCompat due to some issues.
Changing background by getWindow().setBackgroundResource(); Neither in OnResume();
I guess it's an issue with MaterialComponents lib. I guess.
'can show any piece of code if necessary.
EDIT: manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="packageName"
>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="AppClassPath"
android:allowBackup="true"
android:icon="#mipmap/logo"
android:label="#string/app_name"
android:roundIcon="#mipmap/logo_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=SplashScreenPath
android:theme="#style/AppTheme.Launcher">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity android:name=MainActivityPath />
</application>
</manifest>
EDIT #2:
Removed any functionality, leaving OnCreate() empty. No effect, so no problems with external libs.
help
Ok, the issue was with an external lib, called 'com.infideap.drawerbehavior:drawer-behavior:1.0.1'. Will try to figure out what was wrong and post a proper solution.Yeah.
Related
It takes 7-10 seconds, I want to know there is a way to reduce the time. Before I installed the splash screen, the home page is loaded in 2-3 seconds. I have installed react-native-splash-screen package and configured the android files automatically by using #bam.tech/react-native-make.
Never tried on a real device, if you want to know.
MainActivity.java
package com.myApp;
import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
#Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashScreenTheme);
super.onCreate(savedInstanceState);
}
#Override
protected String getMainComponentName() {
return "myApp";
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myApp">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:allowBackup="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
splashscreen.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/splashprimary" />
<item>
<bitmap
android:gravity="center"
android:src="#drawable/splash_image" />
</item>
</layer-list>
styles.xml
<resources>
<style name="SplashScreenTheme" parent="SplashScreen_SplashTheme">
<item name="colorPrimaryDark">#color/splashprimary</item>
<item name="android:statusBarColor">#color/app_bg</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">#000000</item>
<!-- Add the following line to set the default status bar color for all the app. -->
<item name="android:statusBarColor">#color/app_bg</item>
<!-- Add the following line to set the default status bar text color for all the app
to be a light color (false) or a dark color (true) -->
<item name="android:windowLightStatusBar">false</item>
<!-- Add the following line to set the default background color for all the app. -->
<item name="android:windowBackground">#color/app_bg</item>
</style>
</resources>
Try adding this in Style.xml
<item name="android:windowDisablePreview">true</item>
This will remove the white screen which appears in the start.
My app is failing to run in the emulator. The error cited is java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I've read a number of similar questions, including:
.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
ActionBarCompat: java.lang.IllegalStateException: You need to use a Theme.AppCompat
But none of these have worked.
The code in the res>values>styles.xml file is:
<resources>
<style name = "AppBaseTheme" parent = "TextAppearance.AppCompat">
<item name = "android:colorPrimary">#android:color/holo_blue_bright</item>
<item name = "android:colorPrimaryDark">#android:color/holo_blue_dark</item>
<item name = "android:colorAccent">#android:color/holo_red_dark</item>
</style>
</resources>
The code in the src>main>AndroidManifest.xml file is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.hbpm1">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppBaseTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I'd be very grateful if anyone could help :)
Application theme can not be <style name = "AppBaseTheme" parent = "TextAppearance.AppCompat">, because TextAppearance theme can't be used for Application theme at all. So, use any Theme.AppCompat as the default theme for your application.
For this, I can give an example:
<style name = "AppBaseTheme" parent = "Theme.AppCompat">
or
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
etc.
Hope it will work
my Splash activity doesn't change, it only changes if I change the name to another.
For example:
"SplashActivity" - Start with a Modification
If I change the theme to another color, I need to rename the activity to:
"SplashActivityy" or some other name than it was.
If I go back to the name "SplashActivity" the modification goes back to later.
Already formatted and cleared cache of android studio, this did not help!
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.cobaiascreen">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name=".App"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".SplashActivity"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
SplashActivity.java
package com.example.cobaiascreen;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Hiding Title bar of this activity screen */
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
//Making this activity, full screen */
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
App.java
package com.example.cobaiascreen;
import android.app.Application;
import android.os.SystemClock;
import java.util.concurrent.TimeUnit;
public class App extends Application {
#Override
public void onCreate() {
super.onCreate();
// Don't do this! This is just so cold launches take some time
SystemClock.sleep(TimeUnit.SECONDS.toMillis(3));
}
}
Styles.xml
<resources>
<!-- 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>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
</resources>
background_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/colorPrimaryDark"/>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/icon"/>
</item>
</layer-list>
EDIT: problems just like mine:
Splash Theme is not changing anymore
EDIT 2:
I asked a question in a thread to find out what was going on in my code, after a while fidgeting I didn't find walks on the internet related.
Already tried to clear cache, recreate the application, cleared the cache of files, already did everything in android studio.
After a while I found something talking to restart the application that would appear to change.
But I do not want the user to install my application to have to restart the application to appear the changes in the theme. How can I solve this problem?
As i Deeply analysed the code and i found no reason for that "What you are saying" in the code. So what could be a reason according to me is:
Maybe that you have multiple drawable folder and the file background_splash.xml is present in your device specific drawable folder that might be drawable-xxhdpi and also in drawable
& most probably you are doing change in drawable that don't relates to your device.
So kindly verify it, Same for styles also "if applicable".
other measures you can take are
Make Instant run disable.
Uninstall the app after delete data and
clear cache from app info> storage option of phone and then install again.
Hope any of the above technique will work for you.
Try this:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
Are you sure that android.intent.action.MAINACTIVITY exists?
There are issues with the incremental build system "Instant Run" of android studio. This is why they have introduced new/improved incremental build called "Apply Changes" as result of project Marble. It is available in android studio version 3.5. Please see the documentation here
Try to change android:allowBackup="true" to android:allowBackup="false". Install the app. Then completely deinstall it. Install it again. Look at the theme. Then change the theme and reinstall - check if the theme is changed.
I want to change the background colour of the action bar and maybe the text colour too. This question has already asked here but I do not understand it.
Do I need to make a new xml file with this:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
And where should I save it? what folder?
and how to set this as my theme?
Thanks in advance.
You should save this xml into values folder, like themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
And you should select this theme in AndroidManifest like:
<application android:theme="#style/MyTheme">
Try this way... simple create a new color xml in drawable folder..
somecolor.xml
<?xml version="1.0" encoding="utf-8"?>
<color xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#e03456">
</color>
then in onCreate:
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.somecolor));
if you wish to change text color:
int titleId = getResources().getIdentifier("action_bar_title", "id","android");
TextView yourTextView = (TextView) findViewById(titleId);
yourTextView.setTextColor(getResources().getColor(android.R.color.white));
Here is how you change the color of Action Bar (only a few steps):
Use Android Action Bar Style Generator to general all style xml for
your application. It's a web tool,
http://android-ui-utils.googlecode.com/hg/asset-studio/dist/index.html.
The web allows you to generate styles (color, background ... etc)
necessary for the Action Bar. Here is the screen shot of the web
tool.
The tool generates sample
resources icons, images, style xml as the followings. Add all
resource files to the application resource drawable area, and update
AndroidManifest.xml application:theme to use the style xml generated
from the tool. The following is the sample styles, images created
from the tool.
I put all xml in res/drawable folder, except for the action bar style file. I put the action bar style file in res/values. The style file contains this line:
<style name="Theme.Example" parent="#android:style/Theme.Holo.Light.DarkActionBar">
Update your AndroidManfest.xml to use the action bar style "Theme.Example" in the main activity which has the action bar.
<activity
android:theme="#style/Theme.Example"
android:name="com.example.restaurant.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The following is the styled action bar I generated for my project.
I've been trying to set a holo theme in Android, but I haven't been able to get it to recognize it. Any ideas?
Posted is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" android:theme="#android:style/Theme.Holo">
<activity
android:name=".TestActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
It gives me the red line under #android:style/Theme.Holo even if I change the minSdkVersion to 11. Any ideas?
Update:
I changed the line <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/> to <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/> and I am still getting the same error.
Update 2:
This ended up being that my target api was specified correctly in the manifest, but not in project properties. Weird, but now as is well.
Eclipse is giving you an error because SDK versions 7-10 won't know what Theme.Holo is. You need to provide separate styles for both platforms to ensure that the correct style will be found at runtime.
In your res/values/styles.xml file, create the following style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyTheme" parent="#android:style/Theme.Black" />
</resources>
In your res/values-v11/styles.xml file, create the following style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyTheme" parent="#android:style/Theme.Holo" />
</resources>
In your AndroidManifest.xml file, use the following line for your application's theme:
android:theme="#style/Theme.MyTheme"
you are trying to use the Holo theme for API Low than Android 4.0 that's why you get the red Line you can:
Use the HoloEverywhere project
Pick the necessary resources for Holo Theme you most want from the
ICS source and create your own custom theme/styles
https://github.com/android/platform_frameworks_base/tree/master/core/res
You ca also try to make use a custom theme for Android Api 7 to 10
and the holo theme for Api 11 and higher, see #Alex Lockwood's
answer.
The Holo theme needs to be updated in all of the style folders. Check under the values folder, values-sw600dp, values-sw720dp-land, values-v11 and values-v14. The theme on values-v14 overrides all other themes on the higher API's.