In my app i want my dialog to be a curved rectangle,so for that i have created a custom style for dialog in my app.The rectangle comes properly but there is also black rectangle behind which i dont want.How to hide that
Style.Xml
<style name="dialog" parent="android:Theme.Holo.Dialog">
<item name="android:background">#drawable/dialog_bg</item>
<item name="android:textColor">#fff</item>
</style>
Curved Rectangle.Xml
<shape
android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#2196F3" />
<corners android:radius="100px" />
<stroke
android:width="3dip"
android:color="#fff" />
</shape>
Try this theme
<style name="ThemeDialogCustom">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowBackground">#color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
</style>
You can apply custom theme to Dialog while initializing like
Dialog dialog = new Dialog(Activity.this, R.style.CustomDialogTheme);
Related
I have defined two styles in Style.xml, I want to change the style programmatically for certain conditions, Min SDK version 21
<style name="CheckOutButtonStyle" parent="#style/Widget.AppCompat.Button.Colored">
<item name="android:layout_height">60dp</item>
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textSize">16sp</item>
<item name="android:padding">0dp</item>
<item name="android:textColor">#color/white_color</item>
<item name="android:layout_margin">#dimen/general_spacing</item>
</style>
<style name="ScanNextItemSecondaryButtonStyle" parent="#style/Widget.AppCompat.Button.Borderless">
<item name="android:layout_height">wrap_content</item>
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:stateListAnimator">#null
</item> <!-- remove the shadow, per UI request -->
<item name="android:textSize">16sp</item>
<item name="android:padding">0dp</item>
<item name="android:minHeight">0dp</item>
<item name="android:minWidth">0dp</item>
<item name="android:background">#null</item>
<item name="android:textColor">#color/colorSecondaryAccent</item>
<item name="android:layout_marginBottom">#dimen/general_spacing</item>
</style
1. Create xml in drawable.
\res\drawable\back_button_answer.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners android:radius="10dip" />
<!-- background -->
<gradient
android:startColor="#D6D7D6"
android:centerColor="#E2E2E2"
android:centerY="0.75"
android:endColor="#D6D7D6"
android:angle="270"
/>
<stroke android:width="2dip" android:color="#fff"/>
</shape>
2. Button btn.setBackgroundResource(R.drawable.back_button_answer);
I need a dialog with custom background color and rounded corners. How can I keep default layout params using custom window background for AlertDialog?
Currently, my dialog has smaller left-right margin than in regular dialog. Also, dialog buttons such as positive and neutral have more shift from the edge of dialog.
<style name="DialogStuffTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowBackground">#drawable/bg_custom</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:gravity">center</item>
</style>
bg_custom.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="270"
android:startColor="#color/Cyan200"
android:endColor="#color/Green200"
android:type="linear" />
<corners
android:radius="#dimen/dialog_corner_radius" />
</shape>
</item>
</selector>
Should use this when creating AlertDialog: new AlertDialog.Builder(context, R.style.MyDialog)
<style name="DialogBarButton" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#color/button_bar_enabled_selector</item>
</style>
<style name="DialogBase" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowMinWidthMajor">#dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">#dimen/dialog_min_width_minor</item>
<item name="android:windowAnimationStyle">#style/Animation.AppCompat.Dialog</item>
<item name="android:buttonBarButtonStyle">#style/DialogBarButton</item>
</style>
<style name="MyDialog" parent="DialogBase">
<item name="android:windowBackground">#drawable/bg_custom</item>
</style>
values/dimens.xml:
<dimen name="dialog_min_width_major">65%</dimen>
<dimen name="dialog_min_width_minor">85%</dimen>
color/button_bar_enabled_selector.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/colorAccent" android:state_enabled="true" />
<item android:color="#color/TextDisabled"/>
</selector>
I don't know why color of dialog bar buttons had changed in this case. To fix this issue I have to use selector with colors for enabled and disabled states.
I got the following background for an edit text:
edit_text_rounded_white.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#66c6c6c6"/>
<stroke android:width="0.1dp"
android:color="#66c6c6c6"/>
<corners android:radius="40dp"/>
</shape>
</item>
</selector>
in my styles.xml I define the following:
<style name="editText">
<item name="android:background">#drawable/edit_text_rounded_white</item>
<item name="android:drawablePadding">5dp</item>
<item name="android:paddingBottom">2dp</item>
<item name="android:paddingTop">2dp</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">10dp</item>
<item name="android:textCursorDrawable">#drawable/edit_text_cursor</item>
<item name="colorControlNormal">#color/colorPrimaryDark</item>
<item name="colorControlActivated">#color/transparentWhite50</item>
</style>
When I set the style via: style="#style/editText" for my editTexts it takes the background but doesnt take the colorControl I set. When I set the style via android:theme="#style/editText" it takes the colorControls but doesnt show the background image. I already tried src and windowBackground instead of background in the style file.
Any ideas how achieve both? Showing background and the colorControls?
Split your style into two:
<style name="editTextStyle">
<item name="android:background">#drawable/edit_text_rounded_white</item>
<item name="android:drawablePadding">5dp</item>
<item name="android:paddingBottom">2dp</item>
<item name="android:paddingTop">2dp</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">10dp</item>
<item name="android:textCursorDrawable">#drawable/edit_text_cursor</item>
</style>
<style name="editTextTheme">
<item name="colorControlNormal">#color/colorPrimaryDark</item>
<item name="colorControlActivated">#color/transparentWhite50</item>
</style>
And then apply both to your view:
<EditText
...
android:theme="#style/editTextTheme"
style="#style/editTextStyle"/>
I am trying to implement a spinner with a custom layout (not the spinner item layout), the outer layout. I want it to look like this:
http://imgur.com/a/U6RzU
I searched stackoverflow and google, but couldn't figure out how to come up with this (beside putting the whole picture as a background)
Thanks a lot in advance
Edit
This is what I tried:
styles.xml
<style name="spinner">
<item name="android:layout_marginTop">6dp</item>
<item name="android:layout_marginBottom">6dp</item>
<item name="android:layout_marginLeft">0dp</item>
<item name="android:layout_marginRight">0dp</item>
<item name="android:padding">10dp</item>
<item name="android:background">#drawable/spinner_bg</item>
<item name="android:popupBackground">#color/red</item>
<item name="android:textSize">15sp</item>
</style>
spinner_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<gradient android:angle="90" android:endColor="#ff0000"
android:startColor="#ff0000" android:type="linear" />
<stroke android:width="0.33dp" android:color="#0fb1fa" />
<corners android:radius="0dp" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape>
</item>
<item android:right="5dp">
<bitmap android:gravity="center_vertical|right" android:src="#drawable/arrow_white_down" />
</item>
</layer-list>
</item>
</selector>
where arrow_white_down is a png of a tiny white arrow (like the one in the link)
I solved it by using a RelativeLayout with the spinner and an image (arrow) beside it, it doesn't look really good in spinnerMode="dropdown" but this is the best I could do
layout
<RelativeLayout
android:id="#+id/spinner_container"
style="#style/spinner_container">
<Spinner
android:id="#+id/spinner"
style="#style/spinner"
android:layout_toLeftOf="#+id/spinner_image"
android:layout_toStartOf="#+id/spinner_image" />
<ImageView
android:id="#+id/spinner_image"
style="#style/spinner_image" />
</RelativeLayout>
styles.xml
<style name="spinner_container">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">35dp</item>
<item name="android:orientation">horizontal</item>
<item name="android:layout_marginTop">6dp</item>
<item name="android:layout_marginBottom">6dp</item>
<item name="android:layout_marginLeft">0dp</item>
<item name="android:layout_marginRight">0dp</item>
<item name="android:background">#color/red</item>
</style>
<style name="spinner">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">0dp</item>
<item name="android:layout_alignParentLeft">true</item>
<item name="android:layout_alignParentStart">true</item>
<item name="android:padding">5dp</item>
<item name="android:textColor">#color/white</item>
<item name="android:background">#color/red</item>
<item name="android:popupBackground">#color/red</item>
<item name="android:textSize">15sp</item>
</style>
<style name="spinner_image">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_margin">5dp</item>
<item name="android:padding">0dp</item>
<item name="android:layout_alignParentRight">true</item>
<item name="android:layout_alignParentEnd">true</item>
<item name="android:adjustViewBounds">true</item>
<item name="android:src">#drawable/bc_spinner_arrow</item>
</style>
where bc_spinner_arrow is a transparent pic of a white arrow and a vertical line (like the one in the question)
I am trying to change the color of an item when it pressed. I used the actionBarItemBackground item in the action bar style, but nothing happens.. The color not changed...
Here my code:
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#color/actionbar_background</item>
<item name="titleTextStyle">#style/ActionBarStyle.Title</item>
<item name="actionBarItemBackground">#drawable/action_bar_item_selector</item>
<item name="android:actionBarItemBackground" tools:ignore="NewApi">#drawable/action_bar_item_selector</item>
</style>
And the selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/pressed_item" android:state_focused="true"/>
<item android:drawable="#drawable/pressed_item" android:state_pressed="true"/>
<item android:drawable="#android:color/transparent"/>
</selector>
And the drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#FF0000"/>
</shape>
What is worng? Someone?
actionBarItemBackground isn't inherit of Widget.ActionBar. You should be placing it in your root theme, wherever you apply your ActionBarStyle, but not in your ActionBarStyle. So, something like:
<style name="Your.Theme" parent="#style/Theme.AppCompat">
<item name="actionBarStyle">#style/ActionBarStyle</item>
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
<item name="actionBarItemBackground">#drawable/action_bar_item_selector</item>
<item name="android:actionBarItemBackground" tools:ignore="NewApi">#drawable/action_bar_item_selector</item>
</style>