seems like I am the only one on SO with such problem. Why, android, why ?...
have a look at the image. Only the title is centered (phew). The other two items... help!
here is the relevant xml mojo
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dl_base"
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"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
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"
android:fitsSystemWindows="false"
tools:context="com.farmdog.farmdog.HelperActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:paddingTop="#dimen/appbar_padding_topbottom"
android:paddingBottom="#dimen/appbar_padding_topbottom"/>
</android.support.design.widget.AppBarLayout>
and the styles:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<!-- colorPrimaryDark wont work on API level < 21 -->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#color/mainBkgndHard</item>
<item name="android:textColor">#color/appTextColor</item>
<item name="android:buttonStyle">#style/ButtonTheme</item>
<!-- attempt taking actionbar shadow away -->
<item name="elevation">0dp</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="actionMenuTextColor">#color/appTextColor</item>
<item name="titleTextColor">#color/appTextColor</item>
<item name="colorControlNormal">#color/appTextColor</item>
<item name="android:layout_centerVertical">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorPrimary">#color/colorActionBar</item>
</style>
You have set toolbar paddingTop and paddingBottom. You should remove them. I hope it will help resolve your problem.
Related
this is how my activity_main.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<!-- the root view must be the DrawerLayout -->
<androidx.drawerlayout.widget.DrawerLayout
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:id="#+id/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="HardcodedText"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
/>
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation_view"
style="#style/Widget.Custom.NavigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/header_navigation_drawer"
app:menu="#menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
This is how my theme looks like:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.CardsXML1" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/white</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
</style>
</resources>
I want to make drawer cover the status bar. Everything I've treid is in those pieces of code.
I used android:fitsSystemWindows="true" in activity_main.xml
and in theme i placed windowActionBar, windowNoTitle and android:windowTranslucentStatus parameters
but it still doesn't work.
Keep in mind that I want to use MaterialComponents in themes!
I was using Material design 1.1.0
For Tabs with Viewpager2 . I updated it to '1.2.0-alpha05' Material library version it was working fine for single module but was crashing for another module where I've developed my custom material designed TextInputLayout. I changed theme from 'Theme.AppCompat.Light.NoActionBar' to Theme.MaterialComponents.Light.NoActionBar and crash fixed. After fixing crash and upgrading theme it is showing me white floating label , buttons , indiators etc anyone please guide me where am I doing wrong.?
GITHUb Issue Ticket Link :
https://github.com/material-components/material-components-android/issues/1207
TextInputLayout
Style.xml (Old File)
#color/white
#color/colorPrimary_New
#color/a465661
old file had conflict with material while using AppCompact with parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense" after updating to 1.2.0-alpha05 it was resolved but style background is not working now
Library
materialVersion = '1.2.0-alpha05'
"com.google.android.material:material:$materialVersion"
.XML (Design)
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout"
style="#style/contentInputLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_8dp"
android:paddingStart="5dp"
android:paddingLeft="5dp"
app:helperTextEnabled="true"
android:layout_marginLeft="#dimen/_8dp"
android:layout_marginEnd="#dimen/_8dp"
android:layout_marginRight="#dimen/_8dp"
app:errorEnabled="false"
app:layout_constraintBottom_toTopOf="#+id/errorTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:hint="#string/EnterMobileNumber">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/textInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:gravity="start"
android:textDirection="anyRtl"
tools:text="0335510023"
android:background="#null"
android:paddingEnd="#dimen/inputFieldPadding_36dp"
android:paddingRight="#dimen/inputFieldPadding_36dp" />
</com.google.android.material.textfield.TextInputLayout>
Style.xml
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar" >
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/white</item>
<item name="colorPrimaryDark">#color/green</item>
<item name="colorAccent">#color/a465661</item>
</style>
<style name="contentInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="boxStrokeColor">#color/border_stroke_grey</item>
<item name="android:textColor">#color/black</item>
<item name="android:textStyle">normal</item>
<item name="errorTextAppearance">#style/error_label</item>
<item name="counterOverflowTextAppearance">#style/AppTheme.TextFloatLabelAppearance</item>
<item name="android:actionOverflowButtonStyle">#style/AppTheme.TextFloatLabelAppearance
</item>
<item name="hintTextAppearance">#style/text_label</item>
</style>
<style name="text_label" parent="TextAppearance.Design.Hint">
<item name="android:textSize">#dimen/title_heading_12sp</item>
<item name="colorControlNormal">#color/black</item>
<item name="colorControlActivated">#color/black</item>
<item name="colorControlHighlight">#color/black</item>
</style>
<style name="text_label_green" parent="TextAppearance.Design.Hint">
<item name="android:textSize">#dimen/title_heading_12sp</item>
<item name="colorControlNormal">#color/green_field</item>
<item name="android:background">#null</item>
<item name="colorControlActivated">#color/green_field</item>
<item name="colorControlHighlight">#color/green_field</item>
</style>
<style name="AppTheme.TextFloatLabelAppearance" parent="text_label">
<!-- Floating label appearance here -->
<item name="android:textColor">#color/label_title_black</item>
<item name="android:textSize">#dimen/title_heading_12sp</item>
<item name="android:background">#android:color/transparent</item>
<item name="colorControlNormal">#color/label_title_black</item>
<item name="colorControlHighlight">#color/label_title_black</item>
<item name="colorControlActivated">#color/label_title_black</item>
</style>
<style name="material_edit_text" parent="Widget.AppCompat.EditText">
<item name="android:paddingStart">50dp</item>
<item name="android:paddingLeft">50dp</item>
<item name="android:background">#null</item>
<item name="android:textSize">16sp</item>
</style>
<style name="error_label" parent="TextAppearance.Design.Hint">
<item name="android:textSize">0sp</item>
<item name="android:textColor">#color/red</item>
<item name="android:visibility">gone</item>
</style>
<style name="BtnCustomStyle">
<item name="android:background">#drawable/btn_confirm_selector</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:textSize">15dp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">46dp</item>
<item name="android:layout_marginStart">10dp</item>
<item name="android:layout_marginEnd">10dp</item>
<item name="android:textAllCaps">false</item>
<item name="android:foreground">android:attr/selectableItemBackground</item>
</style>
Style(v27).xml (deleted file)
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/white</item>
<item name="colorPrimaryDark">#color/colorPrimary_New</item>
<item name="colorAccent">#color/a465661</item>
<item name="android:windowLayoutInDisplayCutoutMode">never</item>
</style>
Update
"Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
this line was causing crash while using appCompact Theme.
Read topic on material design UI update. According to this document I've to add few attributes that are below!
<!-- New MaterialComponents attributes. -->
<item name="colorOnPrimary">#color/whitee</item>
<item name="colorOnSecondary">#color/colorPrimary_New</item>
<item name="colorOnSurface">#color/a465661</item>-->
<item name="colorSurface">#color/a465661</item>-->
<item name="colorOnBackground">#212121</item>-->
<item name="android:colorBackground">#color/background</item>
<item name="colorError">#F44336</item>-->
<item name="colorOnError">#FFFFFF</item>
but , I tried changing color for TextInputLayout its working fine but for button its not. anyone please guide me how to handle this with new material design.?
update :
android:theme="#style/Theme.MaterialComponents.Light"
add the above-mentioned theme to the widget and it will solve your issue.for example.
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:theme="#style/Theme.MaterialComponents.Light"
app:itemIconTint="#drawable/bottom_navigation_background"
app:itemTextColor="#drawable/bottom_navigation_background"
android:layout_alignParentBottom="true"
app:menu="#menu/navigation"
app:labelVisibilityMode="labeled"
app:itemTextAppearanceActive="#style/BottomNavigationActive"
app:itemTextAppearanceInactive="#style/BottomNavigationInactive" />
I'm developing an android app and I'm trying to use a string resource to store my table title and a style to store my TextAppearance as below:
string:
<resources>
<string name="app_name">DatabaseApp</string>
<string name="table_title">2019 Staff Database</string>
</resources>
style:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="TextStyle" parent="android:TextAppearance">
<item name="android:textSize">20sp</item>
<item name="android:textColor">20sp</item>
</style>
</resources>
Question: Whenever I introduce the...style="#style/TextStyle"...the table title text changes to TextView, I cant figure out the issue, somebody to help me out. What could be the problem?
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/table_title"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:gravity="center"
style="#style/TextStyle"/>
<TableRow>
<!--My other xml codes here-->
</TableRow>
You have declared in your style.xml:
<item name="android:textColor">20sp</item>
I believe android:textColor will not accept a sp or dp value, rather use a color in hex or any resource existing in colors.xml
I made new style in styles.xml file and am trying to use it at the TextView objects in activity_main.xml file but I keep getting error: cannot resolve flag. What's wrong? I was trying to make other styles and it's the same error.
Styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#ff0000</item>
<item name="colorPrimaryDark">#ffffff</item>
<item name="colorAccent">#19df19</item>
</style>
<style name="pytanie">
<item name="android:textSize">20sp</item>
<item name="android:textAllCaps">true</item>
<item name="android:textStyle">italic</item>
<item name="android:textColor">000000</item>
<item name="android:textColorHighlight">#ff0000</item>
</style>
In main_activity.xml:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="pytanie numer 1"
android:textStyle="#styles/pytanie"/>
<Button
android:id="#+id/info_button"
android:layout_width="0dp"
android:layout_weight="1"
android:textColor="#color/white"
android:background="#color/colorPrimary"
android:onClick="getInformation"
android:text="#string/information"
android:layout_height="48dp" />
I have selector below I want to use in button and use background color also.Is there any way?
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/btn_preess" android:state_pressed="true"/>
<item android:drawable="#color/btn_preess1" android:state_focused="true"/>
<item android:drawable="#color/btn_preess1"/>
</selector>