Android v21 Theme.Appcompat color accent is ignored, no padding on dialogs
About the accent color. You are using a AppCompat theme so you should remove Android from the namespace inside your theme.
<style name="AppTheme_Light" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/abc1</item>
<item name="colorPrimaryDark">@color/abc2</item>
<item name="colorAccent">@color/abc3</item>
</style>
About the dialog. AppCompat doesn't support it (as I know).
You can try to use this style in your values-v21 folder:
<style name="Theme" parent="FrameworkRoot.Theme">
<item name="android:alertDialogTheme">@style/Theme.AlertDialog</item>
</style>
<style name="Theme.AlertDialog" parent="android:Theme.Material.Light.Dialog.Alert">
<item name="android:colorPrimary">@color/demo_primary_color</item>
<item name="android:colorPrimaryDark">@color/demo_colorPrimaryDark</item>
<item name="android:colorAccent">@color/theme_accent_1</item>
</style>
UPDATE 23/04/2015: SUPPORT LIBRARY V.22.1
The new support library v22.1
works with the Dialog.
You can use an android.support.v7.app.AlertDialog or the new AppCompatDialog.
For example:
import android.support.v7.app.AlertDialog
AlertDialog.Builder builder =
new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
builder.setTitle("Dialog");
builder.setMessage("Lorem ipsum dolor ....");
builder.setPositiveButton("OK", null);
builder.setNegativeButton("Cancel", null);
builder.show();
And use a style like this:
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#FFCC00</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:background">#5fa3d0</item>
</style>
Otherwise you can define in your current theme:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- your style -->
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
</style>
and then in your code:
import android.support.v7.app.AlertDialog
AlertDialog.Builder builder =
new AlertDialog.Builder(this);
Android colorAccent is ignored in the Dialog
Here is a sample code
<style name="DialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="colorAccent">@color/colorPrimaryDark</item>
</style>
Define style while initiating diaolog in activity.
Dialog dialog = new Dialog(mContext, R.style.DialogStyle);
How to use and style new AlertDialog from appCompat 22.1 and above
When creating the AlertDialog
you can set a theme to use.
Example - Creating the Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.MyAlertDialogStyle);
builder.setTitle("AppCompatDialog");
builder.setMessage("Lorem ipsum dolor...");
builder.setPositiveButton("OK", null);
builder.setNegativeButton("Cancel", null);
builder.show();
styles.xml - Custom style
<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<!-- Used for the buttons -->
<item name="colorAccent">#FFC107</item>
<!-- Used for the title and text -->
<item name="android:textColorPrimary">#FFFFFF</item>
<!-- Used for the background -->
<item name="android:background">#4CAF50</item>
</style>
Result
Edit
In order to change the Appearance of the Title, you can do the following. First add a new style:
<style name="MyTitleTextStyle">
<item name="android:textColor">#FFEB3B</item>
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Title</item>
</style>
afterwards simply reference this style in your MyAlertDialogStyle
:
<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
...
<item name="android:windowTitleStyle">@style/MyTitleTextStyle</item>
</style>
This way you can define a different textColor
for the message via android:textColorPrimary
and a different for the title via the style.
Lollipop v21, FragmentDialog doesn't take my activity theme
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.
How to set default color of progress bar
If the suggestion given by @RuslanMatveev as a comment doesn't work, you can try the following.
<style name="MyProgressBar" parent="@style/Widget.AppCompat.ProgressBar">
<item name="android:progressBackgroundTint">@color/colorAccent</item>
<item name="android:progressTint">@color/colorAccent</item>
</style>
and then set the following paraments inside your AppTheme.Base
<item name="android:progressBarStyleHorizontal">@style/MyProgressBar</item>
or
<item name="android:progressBarStyle">@style/MyProgressBar</item
UPDATE
In case the solution above change the shape of your progress bar you can try to just add the following line to your AppTheme.base
<item name="colorControlActivated">@color/accent</item>
Styling the SearchView Widget using support library v21
According to what I have seen in the SearchView source suggestionRowLayout
resource value in SearchView occurs when retrieving the attributes for the SearchView and in the method getSuggestionRowLayout()
. On the other hand the implementation of SuggestionAdapter of v7 library is inflating abc_search_dropdown_item_icons_2line
.
Idea for a workaround:
Try referencing different layout with help of refs.xml
. Make sure you keep same ids for views as in abc_search_dropdown_item_icons_2line
<item type="layout" name="abc_search_dropdown_item_icons_2line">@layout/my_suggestion_row</item>
Related Topics
Designing Android Apps for Tablets
How to Change The Overscroll Color in Android 2.3.1
Change Button Text and Action - Android Development
How to Place App Icon on Launcher Home Screen
Mediarecorder Issue on Android Lollipop
How to Access an Existing Sqlite Database in Android
How to Use Standard Attribute Android:Text in My Custom View
How to Print a Double with Two Decimals in Android
Android: Refreshing The Gallery After Saving New Images
Easier Way to Get View's Id (String) by Its Id (Int)
Apply Two Different Font Styles to a Textview
Signing My Android Application as System App
How to Look-Up a Contact's Name from Their Phone Number on Android
How to Make Space Between Linearlayout Children
When Using Alertdialog.Builder with Edittext, The Soft Keyboard Doesn't Pop
Your Project Path Contains Non-Ascii Characters Android Studio