When changing ActionBarSize, leaves an small margin to layout below - java

I am using the code below for changing actionbar size.
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textAllCaps">false</item>
<item name="android:windowFullscreen">true</item>
<item name="actionBarSize">26.0dip</item>
</style>
Here is my result
Image
Why this margin exists on child?

Related

AppCompat widget that can only be used with a Theme.AppCompat theme (or descendant)

iOS developer here thrown to the wolves of an Android project. I am getting a few error codes that all say something similar to ThemeUtils: View class androidx.appcompat.widget.AppCompatTextView is an AppCompat widget that can only be used with a Theme.AppCompat theme (or descendant). as soon as the following code snippet runs:
view = inflater.inflate(R.layout.f_basic_dashboard_screen, null, false)
My inflater is instantiated as follows:
val inflater: LayoutInflater = LayoutInflater.from(SqueaksApplication.getApplicationInstance())
SqueaksApplication.getApplicationInstance() just returns an instance of public class SqueaksApplication extends Application
Almost every answer I have found to this question points to the project's manifest as the issue and needing to provide a theme for the project. My project's manifest looks like the following:
<application
android:name=".SqueaksApplication"
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning,UnusedAttribute"
tools:replace="android:icon,android:allowBackup">
As you can see my manifest already includes the line android:theme="#style/AppTheme"
My project uses the layout inflator in many different places, but this is the only one I have come across that is throwing errors. Would appreciate any insight, or solutions you may have, thanks!
Edit: As requested this is my styles.xml:
<style name="MainActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:actionMenuTextColor">#FFF</item>
<item name="actionBarStyle">#style/MainActivityTheme.Toolbar</item>
<item name="actionBarTheme">#style/MainActivityTheme.ToolbarOverlay</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="toolbarStyle">#style/MainActivityTheme.Toolbar</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorPrimary">#color/text_primary</item>
<item name="android:textColorSecondary">#color/text_secondary</item>
<item name="android:windowBackground">#color/background</item>
<item name="actionOverflowButtonStyle">#style/MainActivityTheme.ActionOverflow</item>
<item name="alertDialogTheme">#style/AlertDialogTheme</item>
</style>
<style name="AlertDialogTheme" parent="Base.Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">#DE000000</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="MainActivityTheme.ActionOverflow" parent="Base.Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">#drawable/ic_settings</item>
</style>
<style name="MainActivityTheme.Toolbar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="background">#color/colorPrimary</item>
<item name="elevation">4dp</item>
<item name="titleTextAppearance">#style/MainActivityTheme.ToolbarTextAppearance</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
</style>
<style name="MainActivityTheme.ToolbarOverlay" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
</style>
<style name="MainActivityTheme.ToolbarTextAppearance" parent="TextAppearance.AppCompat.Title">
<item name="android:textColor">#81be41</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:actionMenuTextColor">#FFF</item>
<item name="actionBarStyle">#style/Toolbar</item>
<item name="actionBarTheme">#style/ToolbarOverlay</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="toolbarStyle">#style/Toolbar</item>
<item name="android:textColorPrimary">#color/text_primary</item>
<item name="android:textColorSecondary">#color/text_secondary</item>
<item name="android:windowBackground">#color/background</item>
<item name="actionOverflowButtonStyle">#style/ActionOverflow</item>
<item name="alertDialogTheme">#style/AlertDialogTheme</item>
</style>
<style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:windowBackground">#color/colorPrimary</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="ActionOverflow" parent="Base.Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">#drawable/ic_dots_vertical_white</item>
</style>
<style name="Toolbar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="background">#color/colorPrimary</item>
<item name="elevation">4dp</item>
<item name="titleTextAppearance">#style/ToolbarTextAppearance</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
</style>
<style name="ToolbarOverlay" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
</style>
<style name="ToolbarTextAppearance" parent="TextAppearance.AppCompat.Title">
<item name="android:textColor">#81be41</item>
<item name="android:textSize">20sp</item>
</style>
<style name="Splash" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
<style name="squeak_item_popup_menu_animation">
<item name="android:windowEnterAnimation">#anim/squeak_item_popup_menu_animation_enter</item>
<item name="android:windowExitAnimation">#anim/squeak_item_popup_menu_animation_exit</item>
</style>
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<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>
Your issue is the context used: val inflater: LayoutInflater = LayoutInflater.from(SqueaksApplication.getApplicationInstance()).
The ApplicationContext doesn't have your app theme.
You need to pass the Activity, not an Application Context.

DatePickerDialog buttons not showing the label

The two buttons at the bottom will not show the labels. This is how I am instantiating the date picker new DatePickerDialog(classname.this, date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
I am running Android Studio 3.2 Canary and target sdk of 28.
You can use this to apply material button style :
<style name="AppTheme" parent="Theme.MaterialComponents.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:buttonBarPositiveButtonStyle">#style/Widget.MaterialComponents.Button</item>
<item name="android:buttonBarNegativeButtonStyle">#style/Widget.MaterialComponents.Button.TextButton</item>
<item name="android:buttonBarNeutralButtonStyle">#style/Widget.MaterialComponents.Button</item>
</style>
Result : materialDatePicker
Check for <item name="colorAccent">#color/colorAccent</item> in your styles.xml, button text color will be same as value of colorAccent in colors.xml.
Edit:-
Update your style as following, It will work:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.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:buttonBarPositiveButtonStyle">#style/DialogButtonStyled</item>
<item name="android:buttonBarNegativeButtonStyle">#style/DialogButtonStyled</item>
<item name="android:buttonBarNeutralButtonStyle">#style/DialogButtonStyled</item>
</style>
<style name="DialogButtonStyled" parent="Theme.MaterialComponents.Light">
<item name="android:textColor">#color/colorWhite</item>
</style>

android: Not able to find #style/ThemeOverlay.AppCompat.Dark.ActionBar

Hi in my android studio project this is always red: #style/ThemeOverlay.AppCompat.Dark.ActionBar
and this:
#style/ThemeOverlay.AppCompat.Dark.ActionBar
I have tried everything but still now able to solve this. please help me
and by styles.xml is
<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>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorControlNormal">#color/lightBorder</item>
</style>
<style name="deafultSpinner" parent="android:Widget.TextView.SpinnerItem">
<item name="android:padding">0dp</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<!-- new -->
<style name="logo_img">
<item name="android:src">#drawable/logo</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:layout_width">#dimen/logo_width</item>
<item name="android:layout_height">#dimen/logo_height</item>
</style>
<style name="logo_tv">
<item name="android:layout_marginTop">25dp</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">#dimen/logo_text</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:text">RhythmCor</item>
</style>
<style name="logo_img2">
<item name="android:layout_marginTop">50dp</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:layout_width">#dimen/logo_width</item>
<item name="android:layout_height">#dimen/logo_height</item>
<item name="android:src">#drawable/logo</item>
</style>
<style name="logo_img3">
<item name="android:layout_marginTop">100dp</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:layout_width">#dimen/logo_width</item>
<item name="android:layout_height">#dimen/logo_height</item>
<item name="android:src">#drawable/logo</item>
</style>
<style name="status_img">
<item name="android:layout_marginTop">100dp</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:layout_width">#dimen/statusIcon_width</item>
<item name="android:layout_height">#dimen/statusIcon_height</item>
</style>
<style name="logo_tv2">
<item name="android:layout_marginTop">20dp</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">#dimen/screen_text</item>
<item name="android:textColor">#android:color/black</item>
</style>
<style name="logo_desc_tv">
<item name="android:layout_marginTop">25dp</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textSize">#dimen/normal_text</item>
<item name="android:lineSpacingExtra">#dimen/small_line_spacing</item>
</style>
<style name="logo_desc_tv2">
<item name="android:layout_marginTop">40dp</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textSize">#dimen/normal_text</item>
<item name="android:lineSpacingExtra">#dimen/small_line_spacing</item>
</style>
<style name="logo_desc_tv3">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textSize">#dimen/small_text</item>
<item name="android:lineSpacingExtra">#dimen/small_line_spacing</item>
</style>
<style name="welcome_tv1">
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">#dimen/welcome_text1</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:text">Welcome!</item>
</style>
<style name="welcome_tv2">
<item name="android:layout_marginTop">25dp</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">#dimen/welcome_text2</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:lineSpacingExtra">#dimen/normal_line_spacing</item>
<item name="android:text">Keep track of your health\nwith RhythmCor</item>
</style>
<style name="welcome_footer_btns">
<item name="android:background">#null</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:layout_margin">10dp</item>
<item name="android:textSize">#dimen/welcome_btn_text</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="external_buttons">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">40dp</item>
<item name="android:layout_marginBottom">24dp</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:background">#color/colorPrimary</item>
<item name="android:padding">12dp</item>
</style>
<style name="external_buttons1">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">-10dp</item>
<item name="android:layout_marginBottom">20dp</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:background">#null</item>
<item name="android:padding">12dp</item>
</style>
<style name="external_buttons2">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">40dp</item>
<item name="android:layout_marginBottom">40dp</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:background">#color/colorPrimary</item>
<item name="android:padding">12dp</item>
</style>
</resources>
and my dependencies in build.gradle is:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
testCompile 'junit:junit:4.12'
}
I only had to update my android studio and it worked!
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Toolbar style -->
<item name="toolbarStyle">#style/MyToolBarStyle</item>
<!-- Spinner style -->
<item name="spinnerStyle">#style/MySpinner</item>
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/colorPrimary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<!--
colorAccent is used as the default value for colorControlActivated,
which is used to tint widgets -->
<item name="colorAccent">#color/colorAccent</item>
</style>
Use this #style/Theme.AppCompat.Light.DarkActionBar replace of #style/ThemeOverlay.AppCompat.Dark.ActionBar in xml coding.

Cannot Change Action Bar Text Color

I have read several threads on this topic and have implemented the below code. However, I cannot change change the text color of my Action Bar text:
<style name="AppTheme.NoActionBar">
<item name="android:statusBarColor">#android:color/white</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:textColor">#color/white</item>
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
<style name="AppThemeLight" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="android:textColorPrimary">#color/yourColor</item>
</style>
I use Toolbar and this works for me. Too bad i couldn't repeat it with inheritance.

Action bar not showing text and icons on pre Lollipop devices

So my app is almost done. I have Xperia Z1 which runs Android Lollipop and everything looks fine on it.
Today I sent APK file to my friend who have Xperia T which runs on Android 4.3
He said that everything runs perfect, except actionbar is not showing text or icons. It shows text and icons only on activities that have ListViews.
I don't even know what code to past here.. So if anyone could help I would be thankfull. And please write down what code do you want me to copy.
This is how activites look like:
public class BlaBlaBla extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_programi_specijalizacija_ruke);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
and styles
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="elevation">0dp</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="NavigationDrawerStyle">
<item name="android:textSize">14sp</item><!-- text size in menu-->
<item name="android:background">#f2f2f2</item>
<item name="android:listPreferredItemHeightSmall">36dp</item><!-- item size in menu-->
</style>
<style name="AppTheme.BrandedLaunch" parent="AppTheme">
<item name="android:windowBackground">#drawable/branded_logo</item>
</style>
<style name="Theme.MyApp.ActionBar" parent="style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="elevation">0dp</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="elevation">0dp</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="elevation">0dp</item>
<item name="android:windowContentOverlay">#null</item>
/>
</style>
<style name="FullscreenTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">#color/black_overlay</item>
</style>
</resources>
styles v21
<resources>>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:elevation">0dp</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="elevation">0dp</item>
<item name="android:windowContentOverlay">#null</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:navigationBarColor">#color/black</item>
</style>
</resources>
styles v19
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="elevation">0dp</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="NavigationDrawerStyle">
<item name="android:textSize">14sp</item><!-- text size in menu-->
<item name="android:background">#f2f2f2</item>
<item name="android:listPreferredItemHeightSmall">36dp</item><!-- item size in menu-->
</style>
<style name="AppTheme.BrandedLaunch" parent="AppTheme">
<item name="android:windowBackground">#drawable/branded_logo</item>
</style>
<style name="Theme.MyApp.ActionBar" parent="style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="elevation">0dp</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="elevation">0dp</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="elevation">0dp</item>
<item name="android:windowContentOverlay">#null</item>
/>
</style>
<style name="FullscreenTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">#color/black_overlay</item>
</style>
</resources>
And in AndroidManifest all activities have this:
android:theme="#style/ThemeOverlay.AppCompat.ActionBar" />

Categories

Resources