I am testing the splash screen API below Android 12 versions. It is working fine. But when I navigate to another activity a black screen appears before activity apperas.
Here is my values-31/themes file
<style name="Theme.CustomSplashScreenTheme" parent="Theme.SplashScreen">
<item name="android:windowSplashScreenBackground">#android:color/white</item>
<item name="android:windowSplashScreenAnimatedIcon">#mipmap/ic_launcher_round</item>
<item name="android:windowSplashScreenAnimationDuration">300</item>
<item name="postSplashScreenTheme">#style/AppTheme</item>
</style>
this is my main themes.xml file
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:navigationBarColor">#color/primaryDark</item>
<item name="colorPrimary">#color/primary</item>
<item name="colorAccent">#color/primary</item>
<item name="colorPrimaryDark">#color/primary</item>
<item name="android:forceDarkAllowed">true</item>
</style>
<style name="Theme.CustomSplashScreenTheme" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#android:color/darker_gray</item>
<item name="windowSplashScreenAnimatedIcon">#drawable/ic_launcher_background</item>
<item name="windowSplashScreenAnimationDuration">300</item>
<item name="postSplashScreenTheme">#style/AppTheme</item>
</style>
Now, I have to navigate to screen according to the authentication. So, I have made a splash screen activity. Here is the code for it.
class SplashActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
val splashScreen = installSplashScreen()
super.onCreate(savedInstanceState)
splashScreen.setKeepOnScreenCondition { true }
if (sharedPreferenceUtils.preferenceGetBoolean(Utils.PreferenceKey.isLoggedIn, false)) {
startActivity(Intent(this#SplashActivity, HomeActivity::class.java))
} else {
startActivity(Intent(this#SplashActivity, LoginActivity::class.java))
}
finish()
}
}
I have attached the video for the issue I am facing.
Related
I'm using MaterialComponents for Android from material.io.
I have two themes (light and dark). I want to show an DatePickerDialog.
But this is the result:
Here is the code how i show my dialog:
private fun selectDeadline() {
val dialog = DateDialog()
val bundle = Bundle()
bundle.putInt("themeId", themeId)
dialog.arguments = bundle
dialog.show(supportFragmentManager, "")
}
class DateDialog : DialogFragment(), DatePickerDialog.OnDateSetListener {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val date = DateTime.now()
val themeId = arguments!!.getInt("themeId")
return DatePickerDialog(activity!!, themeId, this, date.year, date.monthOfYear - 1, date.dayOfMonth)
}
override fun onDateSet(view: DatePicker?, year: Int, month: Int, day: Int) {
deadlineTitle.text = "$year, $month, $day"
}
}
And last but not least, my themes:
<resources>
<!-- Dark application theme. -->
<style name="AppTheme.Dark" parent="Theme.MaterialComponents.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="toolbarBackground">#color/darkBackground</item>
<item name="toolbarStyle">#style/AppTheme.Dark.Toolbar</item>
<item name="iconColor">#fff</item>
<item name="dividerBackground">#android:drawable/divider_horizontal_dark</item>
<item name="android:statusBarColor">#android:color/black</item>
</style>
<style name="AppTheme.Dark.Toolbar" parent="Widget.AppCompat.Toolbar">
<item name="android:background">#color/darkBackground</item>
<item name="android:elevation">8dp</item>
</style>
<!-- Light application theme. -->
<style name="AppTheme.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="toolbarBackground">#color/lightBackground</item>
<item name="toolbarStyle">#style/AppTheme.Light.Toolbar</item>
<item name="iconColor">#000</item>
<item name="dividerBackground">#android:drawable/divider_horizontal_bright</item>
<item name="android:datePickerDialogTheme">#style/AppTheme.Light.DatePicker</item>
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
</style>
<style name="AppTheme.Light.DatePicker" parent="ThemeOverlay.MaterialComponents.Dialog">
<item name="materialButtonStyle">?android:attr/borderlessButtonStyle</item>
</style>
<style name="AppTheme.Light.Toolbar" parent="Widget.MaterialComponents.Toolbar">
<item name="android:background">#color/colorPrimary</item>
<item name="android:elevation">8dp</item>
</style>
If i don't give themeId as parameter it shows properly on light theme but on dark theme it shows just the light version with white text which is invisible for the user to see because of the white background.
What is the proper way to solve this problem?
Thank you for the question. The Material Components library currently doesn't support dark mode for date and time pickers. We plan to add support for this, please stay tuned.
I am showing a dialog made from Activity. The dialog activity has set no title in onCreate() callback:
public class MyDialogActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set window feature no title
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.my_dialog);
...
}
...
}
I defined a style for the activity:
<style name="Theme.MyDialog" parent="#style/Theme.AppCompat.Light.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="background">#android:color/transparent</item>
<item name="android:windowBackground">#drawable/my_bg</item>
</style>
And in AndroidManifest.xml:
<activity
android:name=".MyDialogActivity"
android:theme="#style/Theme.MyDialog">
</activity>
But when I show the dialog, there is always a title(which shows my app's name) on the dialog.
It is weird not only because it still shows title, but also shows my app's name as title, as you can see, I haven't set any title. It looks like an Android default behaviour, but...how to get rid of the title?
(I am running on Android 5.1.1)
You can try adding the following style to your Activity for imitating a dialog:
<style name="Theme.AppCompat.TranslucentDialog" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#color/colorTransparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
</style>
where colorTransparent is the following:
<color name="colorTransparent">#64000000</color>
Then use it with:
<activity
android:name=".MyDialogActivity"
android:theme="#style/Theme.AppCompat.TranslucentDialog">
</activity>
I have my activity theme as below set.
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="android:colorButtonNormal">#color/colorPrimary</item>
</style>
The activity have a simple FragmentDialog that is started using (Kotlin code)
MyDialogFragment().show(supportFragmentManager, MyDialogFragment.TAG)
The MyDialogFragment does have a Button. Hence I expect the color of the Button is colorPrimary as per the theme. However the color of the Button (on v21) is only grey)
This works on Marshmallow (i.e. v23) and not Lollipop (v21). I haven't tried v22. ... So I guess the v21 doesn't automatically inherit the theme from the activity.
For KitKat and below, this doesn't apply, as it doesn't use 'android:colorButtonNormal'
How should I get my FragmentDialog get the theme that I set on my activity?
I found a way to do it, which is to explicitly define my FragmentDialog theme as below, on top of defining my activity theme.
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="android:colorButtonNormal">#color/colorPrimary</item>
</style>
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="android:colorButtonNormal">#color/colorPrimary</item>
</style>
Then I need to explicitly set it from my FragmentDialog onCreate().
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.MyDialogTheme)
}
Note: It has to be in onCreate as mentioned in https://stackoverflow.com/a/26582301/3286489
I'm still open to more elegant answer if there's any out there.
I have made my custom style for progress dialog, however it has weird borders around it.
Here is the theme:
<style name="AppTheme.Dialog" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:background">#color/colorPrimaryDark</item>
<item name="android:popupBackground">#null</item>
</style>
Any ideas why there is such weird background ?
To remove the colored or white border around the progress dialog have the dialog use a theme that defines a transparent windowBackground
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
When creating the dialog use this theme:
new ProgressDialog(MyActivity.this, R.style.MyDialogTheme);
Please add:
your_progress_dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
to your java.
Hope this helps!
it's related to this question.
But in contrary to alert dialog there is no AppCompat support to ProgressDialog.
I didn't manage to solve the problem , its possible to use the deprected THEME_HOLO_LIGHT
ProgressDialog dialog= new ProgressDialog(this,ProgressDialog.THEME_HOLO_LIGHT);
but you loose all the benefits of AppCompat (like color accent).
Create Two Style
1) API Level less then equal 19
<style name="AppAlertTheme19" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/btngreen</item>
<item name="android:textColorPrimary">#color/transparent</item>
<item name="android:background">#color/transparent</item>
<item name="android:windowBackground">#color/transparent</item>
<item name="android:popupBackground">#null</item>
</style>
2) API Level greater than 19
<style name="AppAlertTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/btngreen</item>
<item name="android:textColorPrimary">#color/transparent</item>
<item name="android:background">#color/white</item>
<item name="android:windowBackground">#color/transparent</item>
<item name="android:popupBackground">#null</item>
</style>
3)and init progress view like this
public class ProgressDialogCustom extends ProgressDialog {
public ProgressDialogCustom(Context context) {
super(context, getStyle());
setMessage("Please Wait ...");
setCancelable(false);
}
private static int getStyle() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
return R.style.AppAlertTheme;
} else {
return R.style.AppAlertTheme19;
}
}
}
I may be late to answer this question, but as I was facing same problem, I resolved it as follows:
I created 2 styles one for above lollipop and one for below it.
API Level greater than 19
<style name="AppAlertTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/white</item>
<item name="android:textColorPrimary">#color/transparent</item>
<item name="android:background">#color/blue</item>
<item name="android:windowBackground">#color/transparent</item>
<item name="android:popupBackground">#null</item>
</style>
API Level less than 19
<style name="AppAlertTheme_api19" parent="android:Theme.Holo.Dialog">
<item name="android:alertDialogStyle">#style/CustomAlertDialogStyle</item>
<item name="android:windowBackground">#color/nlue</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:textColor">#color/white</item>
</style>
<style name="CustomAlertDialogStyle">
<item name="android:bottomBright">#android:color/transparent</item>
<item name="android:bottomDark">#android:color/transparent</item>
<item name="android:bottomMedium">#android:color/transparent</item>
<item name="android:centerBright">#android:color/transparent</item>
<item name="android:centerDark">#android:color/transparent</item>
<item name="android:centerMedium">#android:color/transparent</item>
<item name="android:fullBright">#android:color/transparent</item>
<item name="android:fullDark">#android:color/transparent</item>
<item name="android:topBright">#android:color/transparent</item>
<item name="android:topDark">#android:color/transparent</item>
</style>
Then used this style as follows:
public int getProgressDailogStyle(){
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
return R.style.AppAlertTheme;
} else {
return R.style.AppAlertTheme_api19;
}
}
and finally
progressDialog = new ProgressDialog(context, getProgressDailogStyle());
Hope this helps you..
Once I switched from ActionBarActivity to AppCompatActivity one of the only changes I did was add this line:
<item name="windowNoTitle">true</item>
Here is my entire styles.xml file:
<style name="gptheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="ThemeNoActionBar" parent="gptheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Now, all the new AppCompatDialogs in my code, (which were formerly Dialog d = new Dialog(mContext), all have no titles even though I use setTitle().
Obviously the change I made to the titles specified windowNoTitle but that should only affect the parent activity. I would think, anyway.
How exactly does this new feature work?
// style.xml
<style name="DialogActivity" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="colorAccent">#fff</item>
</style>
// manifest.xml
<activity
android:name=".MyPopupActivity"
android:theme="#style/DialogActivity"/>
// activity
import android.app.Activity;
public class MyPopupActivity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_popup);
}
}