Cannot change text size of com.google.android.material.tabs.TabItem in com.google.android.material.tabs.TabLayout - android-layout

What am I missing to make the TabItem text bigger? I've gone through all similar questions and tried many different statements. I've tried applying a style to the TabLayout as well as the TabItem and nothing seems to work, the text size doesn't change.
Is this capability missing from the material design version?
Thanks
activity_main.xml
<com.google.android.material.tabs.TabLayout
style="#style/TabTheme"
android:layout_width="694dp"
android:layout_height="72dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tabIndicatorHeight="6dp"
app:tabTextAppearance="#style/TabTheme">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clock In" />
styles.xml
<style name="TabTheme">
<item name="android:textSize">40dp</item>
<item name="android:textStyle">normal</item>
<item name="android:textAllCaps">true</item>
<item name="android:textColor">#color/primaryDarkColor</item>
<item name="android:includeFontPadding">false</item>
</style>
I have also tried applying the following style to both TabLayout and TabItem
with no result:
<style name="CustomTabText" parent="TextAppearance.Design.Tab">
<item name="android:textSize">100sp</item>
</style>

It's working now. I've been creating a lot of test projects and this one still had the original theme definition by accident:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
I changed it to a material theme:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
That was the problem

Related

How to make StatusBar Covered by DrawerLayout

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!

Android String and Style Resource Not giving desired change

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

android studio styles.xml cannot servolve symbol

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"/>

Centering the home/homeasup and action menu in an appcompat actionbar

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.

Is there any way to center an image in a button using just the XML in 4.2.2?

I've got a great image of a right arrow and a button to put it in, but I definitely don't want it flush to a side. Is there any way to put it in the center using only the XML?
Here's the relevant code:
<style name="widget.numberPad.actionButton.done.small" parent="widget.numberPad.actionButton.done">
<item name="android:layout_width">90dp</item>
<item name="android:drawableStart">#drawable/ic_arrow_forward_white_48px</item>
<item name="android:gravity">center_horizontal|center_vertical</item>
<item name="android:layout_alignParentBottom">true</item>
<item name="android:layout_centerHorizontal">true</item>
</style>
The button should be exactly 90dp × 90dp, but I don't know how the 48px × 48px image translates into dp.
I've read How to center icon and text in a android button with width set to “fill parent”, but the solution is both in java and deals with a width issue that I do not.
I'm not sure I understand your question, but to center an icon on a button, this is my solution.
Other possibility to keep Button theme.
<Button
android:id="#+id/pf_bt_edit"
android:layout_height="#dimen/standard_height"
android:layout_width="match_parent"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignBottom="#id/pf_bt_edit"
android:layout_alignLeft="#id/pf_bt_edit"
android:layout_alignRight="#id/pf_bt_edit"
android:layout_alignTop="#id/pf_bt_edit"
android:layout_margin="#dimen/margin_10"
android:clickable="false"
android:elevation="20dp"
android:gravity="center"
android:orientation="horizontal"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:clickable="false"
android:src="#drawable/ic_edit_white_48dp"/>
<TextView
android:id="#+id/pf_tv_edit"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/margin_5"
android:clickable="false"
android:gravity="center"
android:text="#string/pf_bt_edit"/>
</LinearLayout>
With this solution if your add <item name="colorButtonNormal">#color/your_color</item> and <item name="colorControlHighlight">#color/your_highlight_color</item> in your activity theme, you can have the Material theme on Lollipop with the shadow and ripple, and for previous versions, flat button with your color and highlight color when you press it.
Additionally, here is this autoresizing solution as a picture:
Lollipop device
On pre-lollipop device
Pre-lollipop device press button

Resources