How to overcome gap between navigation icon and activity label? - android

I want to reduce this space is there any way to do this?
This is my style.xml
<resources>
<!-- 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="listPreferredItemHeightSmall">40dp</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

Add these properties to your Toolbar:
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"

Related

Unable to see Activity in Android Studio

I'm having a problem with my Tab Activity. I can't see anything, like literally nothing. I already changed the style.xml of the activity but it still doesn't work out.
Here is my style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.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="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="Base.ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="Base.ThemeOverlay.AppCompat.Light" />
</resources>

how to bring the icons closer?

I am having my app bar with three icons on it. The space between them looks quite high. How to get them closer
the following is my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowDisablePreview">true</item>
<!-- 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="AppTheme" parent="AppBaseTheme">
<item name="actionOverflowMenuStyle">#style/OverflowMenu</item>
</style>
<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<!-- Required for pre-Lollipop. -->
<item name="overlapAnchor">false</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
Use this theme changing what you think needs to be changed but definitely experiment with the width and height values to find the ones that suit your needs.
<style name="MyTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="colorControlNormal">#android:color/black</item>
<item name="android:actionButtonStyle">#style/myActionButtonStyle</item>
<item name="actionButtonStyle">#style/myActionButtonStyle</item>
</style>
<style name="myActionButtonStyle" parent="Widget.AppCompat.ActionButton">
<item name="android:width">80dp</item>
<item name="android:height">80dp</item>
</style>

Auto background color is black even when I create a new Activity

I don't know if is related with git but after committing my project using git, every Activity's background color is changed even when I create a new Activity.
Why?
My style file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.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="drawerArrowStyle">#style/MyDrawerArrowToggle</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="MyDrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">#color/toolbar_text_color</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlNormal">#color/textColor</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"></style>
</resources>
<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="drawerArrowStyle">#style/MyDrawerArrowToggle</item>
</style>
I changed "Theme.AppCompat.NoActionBar" to "Theme.AppCompat.Light.NoActionBar".
It is worked.Thanks everyone....
Here is the mistake you are using dark theme
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlNormal">#color/textColor</item>

Why Status bar is appearing with shadow?

Status bar of my app is not seem as clear or it appears with some shadow.
This is how my status bar looks:
And it should appear like this:
Why it isn't looking like this?
style.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>
<item name="windowActionBarOverlay">false</item>
<item name="windowActionBar">false</item>
<item name="android:windowBackground">#android:color/white</item>\
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
What's wrong with this? Please help..
Delete this line
<item name="android:statusBarColor">#android:color/transparent</item>
from your values-v21/styles.xml
If you are in android 5 or later you can set the elevation of the actionbar to 0 by below code
getSupportActionBar().setElevation(0);
If not 5 or higher then add below style in your theme
<style name="MyAppTheme" parent="android:Theme.Holo.Light">
<item name="android:windowContentOverlay">#null</item>
</style>

How to inherit style of AlertDialog buttons

I wanna make style of my buttons at fragment like AlertDialog, how can I do it
Which style I should inherit or set for my buttons
My styles.xml
<!-- 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:spinnerItemStyle">#style/Spinner</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Thanks
Here's a quick example of how i have done this in an app. You need to set an alertDialogTheme in your AppTheme. You also can apply styles to the buttons as well. Here's an example using your code.
<!-- 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:spinnerItemStyle">#style/Spinner</item>
<item name="android:alertDialogTheme">#style/AlertDialogTheme</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColor">#android:color/black</item>
<item name="android:textColorPrimary">#android:color/holo_red_dark</item>
<item name="android:textColorSecondary">#android:color/holo_orange_light</item>
<item name="colorAccent">#android:color/holo_purple</item>
<item name="colorControlHighlight">#android:color/holo_purple</item>
<item name="buttonBarNegativeButtonStyle">#style/NegativeButton</item>
<item name="buttonBarPositiveButtonStyle">#style/PositiveButton</item>
</style>
<style name="NegativeButton"
parent="android:Widget.DeviceDefault.Button.Borderless">
<item name="android:textColor">#android:color/holo_green_dark</item>
</style>
<style name="PositiveButton"
parent="android:Widget.DeviceDefault.Button.Borderless">
<item name="android:textColor">#android:color/green</item>
</style>

Categories

Resources