I am trying to change the toolbar spinner dropdown theme strangely this is not happening. It is coming up always dark when I click on the spinner. I would like to have the background grey and text black.
I don't have any actionbar. I am setting everything through toolbar.
Hence I tried the following:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:id="#+id/relativeLayoutID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="left|center"
android:text="#string/register_title"
android:textColor="#color/whiteText"
android:textSize="#dimen/text_size_medium" />
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="80dp"
android:spinnerMode="dropdown"
android:visibility="gone" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
Style xml:
<resources>
<style name="Theme.default" parent="Theme.AppCompat.Light.NoActionBar">
<item name="md_widget_color">#color/numbertext</item>
<item name="android:colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:colorPrimary">#color/colorPrimary</item>
<item name="android:windowContentOverlay">#drawable/toolbar_dropshadow</item>
<item name="android:windowBackground">#android:color/white</item>
<item name="android:editTextColor">#android:color/background_dark</item>
<item name="android:textColor">#android:color/background_dark</item>
<item name="colorControlNormal">#android:color/background_dark</item>
<item name="colorControlActivated">#color/orangeText</item>
<item name="colorControlHighlight">#color/orangeText</item>
<item name="android:statusBarColor">#color/colorPrimary</item>
</style>
<style name="Widget.MyApp.HeaderBar.Spinner" parent="Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:background">?android:selectableItemBackground</item>
<item name="android:dropDownSelector">?android:selectableItemBackground</item>
<item name="android:divider">#color/blackText</item>
<item name="android:overlapAnchor">true</item>
</style></resources>
Update:
Added the following theme:
<style name="MyDarkToolbarStyle" parent="#style/Widget.AppCompat.Spinner.DropDown.ActionBar">
<item name="background">?android:selectableItemBackground</item>
<item name="android:popupBackground">#color/layoutbackground</item>
<item name="android:dropDownSelector">?android:selectableItemBackground</item>
<item name="android:divider">#color/blackText</item>
<item name="android:overlapAnchor">true</item>
</style>
And applied it to the spinner:
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="80dp"
style="#style/MyDarkToolbarStyle"
android:spinnerMode="dropdown"
android:visibility="gone" />
With above settings I could change the dropdown background color but not I am not able to get ripple effect on selection this used to happen before applying the theme to the spinner?
Just add the following to your Spinner the same way you did for your Toolbar:
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
So your final Spinner will look like this:
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="80dp"
android:spinnerMode="dropdown"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:visibility="gone" />
Related
I have the following layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.camera.view.PreviewView
android:id="#+id/viewFinder"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.button.MaterialButton
android:id="#+id/btn_image_select"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="20dp"
app:icon="#drawable/baseline_photo_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
style="#style/MaterialIconButtonCircledDarkTransparentStyle"
/>
<com.google.android.material.button.MaterialButton
android:id="#+id/btn_image_capture"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_margin="20dp"
app:strokeWidth="2dp"
app:strokeColor="#color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
style="#style/MaterialIconButtonCircledLightTransparentStyle"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
With the following style:
<style name="MaterialIconButtonCircledDarkTransparentStyle">
<item name="android:insetLeft">0dp</item>
<item name="android:insetTop">0dp</item>
<item name="android:insetRight">0dp</item>
<item name="android:insetBottom">0dp</item>
<item name="iconPadding">0dp</item>
<item name="iconGravity">textStart</item>
<item name="background">#color/BlackTransparent</item>
<item name="shapeAppearanceOverlay">#style/ShapeAppearanceOverlayMaterialIconButtonCircular</item>
</style>
<style name="MaterialIconButtonCircledLightTransparentStyle" parent="MaterialIconButtonCircledDarkTransparentStyle">
<item name="android:backgroundTint">#color/LightGrayTransparent</item>
</style>
<style name="ShapeAppearanceOverlayMaterialIconButtonCircular" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
<color name="LightGrayTransparent">#80C0C0C0</color>
<color name="BlackTransparent">#6A000000</color>
Which looks like this:
As you can see there is a random pentagon shaped style which is visible when I have a transparent backgroundTint.
Any idea how I can hide the pentagon shaped form?
I tried setting the ripple color to null and other options, but none of them worked unfourtantly.
I'm pretty new to Android, and trying to define a style for my layout.
My layout is as follows:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_margin="10dp"
app:cardCornerRadius="20dp"
app:cardPreventCornerOverlap="true">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/background_test"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/transparent_white"
android:orientation="vertical">
<TextView
android:id="#+id/title"
style="#style/TitleScrollable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" />
<TextView
android:id="#+id/subtitle"
style="#style/SubtitleScrollable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
In my style.xml:
<style name="Title" parent="#style/TextAppearance.MaterialComponents.Headline5">
<item name="android:text">Long Long Title</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">22sp</item>
<item name="android:textColor">#color/primaryDark</item>
</style>
<style name="TitleScrollable" parent="Title">
<item name="singleLine">true</item>
<item name="maxLines">1</item>
<item name="android:ellipsize">marquee</item>
<item name="android:marqueeRepeatLimit">marquee_forever</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
</style>
But my title is still wrapping to next lines.
When i use this style elsewhere it works fine.
When adding maxLines=1 in the layout it works fine.
I am trying to style the material buttons using the new styles offered by the implementation 'com.google.android.material:material:1.0.0'
library. The issue is that the buttons are not styling properly. For example, I have 2 different activities using the exact same theme, with the exact same code for the button but on refuses to use the right style, on the Android preview screen it looks right but in the actual app its not.
Also, I am manually overriding the style of a group of buttons by setting style="myButtonStyleWhatever" but that just gets ignored as well. This is getting very frustrating so I would love if someone could help.
Styles-v11
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyMaterialTheme.Base" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimaryDark</item>
</style>
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="colorPrimary">#364c70</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
<style name="WhiteButtons" parent="Widget.MaterialComponents.Button">
<item name="android:background">#ffff</item>
<item name="android:textColor">#000</item>
</style>
</resources>
Styles-v21
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyMaterialTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">#android:transition/move</item>
<item name="android:windowSharedElementExitTransition">#android:transition/move</item>
</style>
<style name="MyMaterialTheme.Base" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimaryDark</item>
</style>
</resources>
Styles
<resources>
<style name="MyMaterialTheme.Base" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimaryDark</item>
</style>
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="colorPrimary">#364c70</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
<style name="WhiteButtons" parent="Widget.MaterialComponents.Button">
<item name="android:background">#ffff</item>
<item name="android:textColor">#000</item>
</style>
</resources>
Code used for the button
<com.google.android.material.button.MaterialButton
android:id="#+id/get_suggestions"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="#dimen/_65sdp"
android:layout_height="wrap_content"
android:layout_marginStart="163dp"
android:layout_marginTop="83dp"
android:layout_marginEnd="163dp"
android:layout_marginBottom="219dp"
android:text="SEARCH"
android:textSize="#dimen/_9sdp"
app:cornerRadius="100dp" />
Not meant to look like that
<!-- MAIN CONTENT -->
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/xmlns:app="
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:windowSoftInputMode="adjustNothing"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp"
sothree:umanoParallaxOffset="100dp"
sothree:umanoDragView="#+id/dragger"
sothree:umanoOverlay="true"
sothree:umanoScrollableView="#+id/dragView">
<androidx.drawerlayout.widget.DrawerLayout
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer"
android:focusableInTouchMode="true"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:id="#+id/parent"
android:layout_height="match_parent">
<com.mancj.materialsearchbar.MaterialSearchBar
android:id="#+id/search"
android:layout_width="#dimen/_233sdp"
android:layout_height="#dimen/_58sdp"
android:layout_marginStart="8dp"
android:layout_marginTop="5dp"
android:elevation="100dp"
android:imeOptions="actionSearch"
sothree:layout_constraintStart_toStartOf="parent"
sothree:layout_constraintTop_toTopOf="parent"
tools:ignore="UnusedAttribute" />
<com.google.android.material.button.MaterialButton
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:id="#+id/get_suggestions"
android:layout_width="#dimen/_65sdp"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginTop="10dp"
app:cornerRadius="100dp"
android:text="SEARCH"
android:textSize="#dimen/_9sdp"
sothree:layout_constraintEnd_toEndOf="parent"
sothree:layout_constraintTop_toTopOf="parent" />
<com.mapbox.mapboxsdk.maps.MapView
android:id="#+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraTargetLat="46.885"
mapbox:mapbox_cameraTargetLng="24.679"
mapbox:mapbox_cameraTilt="20"
mapbox:mapbox_cameraZoom="4"
mapbox:mapbox_styleUrl="mapbox://styles/sudafly/cjm89d4011nu02smk5a7e0d8h"
sothree:layout_constraintBottom_toBottomOf="parent"
sothree:layout_constraintEnd_toEndOf="parent"
sothree:layout_constraintStart_toStartOf="parent"
sothree:layout_constraintTop_toTopOf="parent">
</com.mapbox.mapboxsdk.maps.MapView>
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/nav_menu"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:menu="#menu/navigation_menu"
/>
</androidx.drawerlayout.widget.DrawerLayout>
<!-- SLIDING LAYOUT -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/dragView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:clickable="true"
android:focusable="false"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:background="#2a2e41"
android:id="#+id/dragger"
android:orientation="horizontal">
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="#string/search_for_airports"
android:textColor="#d2d4e0"
android:textSize="20dp" />
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drag"
android:background="#eceff1">
<LinearLayout
android:id="#+id/Lin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eceff1"
android:elevation="#dimen/_20sdp"
android:theme="#style/AppTheme.AppBarOverlay"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.tabs.TabLayout
android:id="#+id/tab"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.google.android.material.tabs.TabLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp">
<include layout="#layout/charts_v2" />
<include layout="#layout/content_main" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.AppBarLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
The styles you've posted don't make a ton of sense.
You are showing ToolBarStyle and WhiteButtons styles but you're not using them anywhere.
You have MyMaterialTheme (as opposed to MyMaterialTheme.Base) in one of the files; I hope you aren't expecting this to be automatically inherited from by MyMaterialTheme.Base, since specifying a parent overrides the dot-notation inheritance.
All three files have the same contents for MyMaterialTheme.Base; why bother specifying it in three places?
Additionally, none of the styles you've posted seem like they would affect MaterialButton widgets (except for colorPrimary). So it's hard to know exactly where your problem lies.
All that said, the list of attributes supported by MaterialButton is available in the GitHub documentation. Notably, android:background is not supported by MaterialButton. From the JavaDoc:
Do not use the android:background attribute. MaterialButton manages its own background drawable, and setting a new background means MaterialButton can no longer guarantee that the new attributes it introduces will function properly. If the default background is changed, MaterialButton cannot guarantee well-defined behavior.
I suspect that what you're seeing is a combination of different colorPrimary definitions on the two screens and the fact that android:background is not supported.
If you want to manually override the button's background color, use the app:backgroundTint attribute on your <MaterialButton> tag. If you want to specify that in a <style> tag, it doesn't use a namespace:
<item name="backgroundTint">#color/your_background_color</item>
I have applied a theme to my app but when I use textColor properties it override all other properties like textColorPrimary.
<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>
<item name="android:windowBackground">#color/windowBackground</item>
<item name="android:textColorPrimary">#FF4081</item>
<item name="android:textColorSecondary">#186925</item>
<item name="colorControlActivated">#FF0000</item> <!-- for check box when checked -->
<item name="colorControlNormal">#bbc40c</item> <!-- for check box when normal -->
<item name="colorButtonNormal">#325289</item>
<!--<item name="android:textColor">#084fe9</item>-->
<item name="android:windowAnimationStyle">#style/WindowAnimationTransition</item>
<!--<item name="android:windowActivityTransitions">true</item>
<item name="android:windowEnterTransition">#android:transition/slide_right</item>
<item name="android:windowExitTransition">#android:transition/slide_left</item>-->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
<style name="HeaderText" parent="#android:style/TextAppearance.Large">
<item name="android:textColor">#ffffffff</item>
<item name="android:textSize">12dp</item>
</style>
<style name="WindowAnimationTransition">
<item name="android:windowEnterAnimation">#android:anim/fade_in</item>
<item name="android:windowExitAnimation">#android:anim/fade_out</item>
</style>
my Layout file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/questionNumberTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/scoreTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:layout_marginEnd="16dp"
android:text="Score : 20"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/iconIv"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toStartOf="#+id/scoreTv"
app:layout_constraintStart_toEndOf="#+id/questionNumberTv"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#tools:sample/avatars[11]" />
<TextView
android:id="#+id/questionTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:text="TextView"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/iconIv" />
<Button
android:id="#+id/fiftyfiftyBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/radioGroup2" />
<RadioGroup
android:id="#+id/radioGroup2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/questionTitle">
<RadioButton
android:id="#+id/option1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="#+id/option2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="#+id/option3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="#+id/option4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
<TextView
android:id="#+id/votesTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:drawableLeft="#drawable/ic_expand_less_green_24dp"
android:text="20"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fiftyfiftyBtn" />
<TextView
android:id="#+id/commentCountTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:drawableLeft="#drawable/ic_expand_less_green_24dp"
android:text="35"
android:textSize="16sp"
app:layout_constraintStart_toEndOf="#+id/votesTv"
app:layout_constraintTop_toBottomOf="#+id/fiftyfiftyBtn" />
</android.support.constraint.ConstraintLayout>
when I Uncomment android:textColor , android:textColorPrimary color is override by android:textColor. I want my title/large text to use textColorPrimary and for medium and small I wanna use textColorPrimaryDark as said in their documentation.
before that the button text color is set by the textColorPrimary.
How could I use two text Color scheme for whole my app. using textColorPrimary and textColorPrimaryDark.
Or I have to create two textStyle and set them to each View. Is there a better approach to achieve what I want.
You need to define two styles and set your desired attributes there. It is cleaner to read and understandable. And also good behaviour to set your own style in textview.
Here is a sample you should do:
<style name="textStyle1" parent="android:TextAppearance">
<item name="android:textColor">#color/textColorPrimary</item>
<item name="android:textStyle">bold</item>
<item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
<item name="android:gravity">start</item>
<item name="android:textSize">22sp</item>
</style>
<style name="textStyle2" parent="android:TextAppearance">
<item name="android:textColor">#color/textColorPrimaryDark</item>
<item name="android:textStyle">normal</item>
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
<item name="android:gravity">start</item>
<item name="android:textSize">18sp</item>
</style>
Then use this style on your expected textview like this:
<TextView
android:id="#+id/tv_name"
style="#style/textStyleMedium"
........ />
Remove the below tags on your app theme:
<item name="android:textColorPrimary">#FF4081</item>
<item name="android:textColorSecondary">#186925</item>
<!-- <item name="android:textColor">#084fe9</item> -->
Purpose of different color:
TextColor is just the xml attribute to set a color to the text of any given view.
TextColorPrimary is the default text color for enabled buttons and Large Textviews.
TextColorSecondary is the default text color for Medium and Small Textviews.
colorPrimaryDark is the color of the status bar.
In order to achieve this you should remove textColor that override other colors.
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
inside your textView in xml . Then it will apply it to all your View. In this manner you don't have to set style to all ..
I have an activity with the following theme
<style name="CustomDialogTitle" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/PauseDialogTitle</item>
</style>
<style name="PauseDialogTitle" parent="#android:style/TextAppearance.DialogWindowTitle">
<item name="android:gravity">center_horizontal</item>
<item name="android:windowTitleSize">50dip</item>
<item name="android:height">70dip</item>
<item name="android:maxLines">2</item>
<item name="android:singleLine">false</item>
</style>
<style name="DialogWindowTitle">
<item name="android:textAppearance">#android:style/TextAppearance.DialogWindowTitle</item>
</style>
and this is the custom title layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dip"
android:orientation="vertical" >
<TextView
android:id="#+id/first_line_title_text"
style="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:text="first line" />
<TextView
android:id="#+id/second_line_title_text"
style="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:text="second line" />
I can only see one line of the title layout
What's causing the title to show only one line with fixed height ?
although i'm specifying height in the layout and style