how to call a another layout file inside a styles in android? - android

i custom the Theme in android Widget.TabWidget android:tablayout
and overide the style of tabwidget in my ownway not using #android because
i want to custom my style of API 10 below same like API11+
<resources>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="AppBaseTheme" parent="android:Theme">
<!-- Window -->
<item name="android:windowNoTitle">true</item>
<item name="android:tabWidgetStyle">#style/MyTabWidget</item>
</style>
<!-- TabWidget -->
<style name="MyTabWidget" parent="android:style/Widget.TabWidget">
<item name="android:textAppearance">#style/MyTabWidgetTextAppearance</item>
<item name="android:gravity">center|center</item>
<item name="android:tabLayout"> HOW TO CALL api_1_10_indicator.xml LAYOUT FROM MY RES LAYOUT </item>
</style>
<!-- TabWidget TextAppearance -->
<style name="MyTabWidgetTextAppearance" parent="android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">14sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">#color/select_tabwidget_text_color</item>
</style>
</resources>
my res/layout/api_1_10_indicator.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dip"
android:layout_height="48dip"
android:layout_weight="1"
android:layout_marginStart="-3dip"
android:layout_marginEnd="-3dip"
android:background="#color/api_1_10_tab_indicator">
<ImageView android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
<TextView android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="?android:attr/tabWidgetStyle"
/>
</RelativeLayout>
if i use <item name="android:tablayout">#layout/api_1_10_indicator</item>
its not working icant call my own tablayout for the tabwidget that i custom.
HOW TO DO IT?

Related

Button background color is not showing in my android activity

I created a calculator activity as a part of a bigger app, and created a theme, and style for different components. yet, when I assign a background color of orange to the "buttonOperator" styles it doesn't show in the activity on the buttons that are using this style, appreciate explaining to me what i did wrong and maybe how/what tools can be used to troubleshoot such layout problems in android studio if such tools or methods are available.
below is the code relevant to the issue:
calculatorActivity.xml
<\?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/light_Black"
android:orientation="vertical"
android:theme="#style/Theme.UnitConverterAdvance.Calculator"
tools:context=".CalculatorActivity">
<LinearLayout style="#style/buttonRow">
<Button
style="#style/buttonNumber"
android:text="#string/button_7" />
<Button
style="#style/buttonNumber"
android:text="#string/button_8" />
<Button
style="#style/buttonNumber"
android:text="#string/button_9" />
<Button
style="#style/buttonOperator"
android:text="#string/button_division" />
</LinearLayout>
<LinearLayout style="#style/buttonRow">
<Button
style="#style/buttonNumber"
android:text="#string/button_0" />
<Button
style="#style/buttonNumber"
android:text="#string/button_dot" />
<Button
style="#style/buttonOperator"
android:text="#string/button_equal" />
<Button
style="#style/buttonOperator"
android:text="#string/button_plus" />
</LinearLayout>
</LinearLayout>
Style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="buttonRow">
<item name="android:layout_weight">1</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">0dp</item>
</style>
<style name="buttonNumber">
<item name="android:layout_weight">1</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">match_parent</item>
<item name="android:background">#null</item>
<item name="android:textSize">25sp</item>
<item name="android:textColor">#color/white</item>
</style>
<style name="buttonOperator">
<item name="android:layout_weight">1</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">match_parent</item>
<item name="backgroundColor">#color/orange</item>
<item name="android:textSize">25sp</item>
<item name="android:textColor">#color/white</item>
</style>
</resources>
Theme.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.UnitConverterAdvance" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- 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/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<style name="Theme.UnitConverterAdvance.Calculator" parent="Theme.AppCompat">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/light_Black</item>
<item name="colorPrimaryVariant">#color/orange</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
</style>
</resources>
////Try to give manually in .xml file it. It works fine.
<Button
android:id="#+id/btn_proceToPay"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_below="#id/rl3"
android:layout_marginTop="20dp"
android:background="#color/primaryBackgroung"
android:enabled="false"
android:text="Proceed To Pay"
android:textAllCaps="false"
android:textColor="#color/whiteText"
android:textSize="16sp"
android:textStyle="bold" />
as indicated by commonsware in his comment, the answer is in using the backgroundTint instead of the backgroundColor in the Style.xml. or changing 'button' tag into 'android.widget.Button'.
Because since Android Studio 4.1 any Button elements in a layout get turned into MaterialButton widgets, which ignores background attribute.
for more details refer to commonsware answer

How to use MaterialButtonToggleGroup without inheriting from a Material Components theme

I want to create MaterialButtonToggleGroup without having my AppTheme inheriting Theme.MaterialComponents.Light.DarkActionBar. So I tried to inherit Theme.MaterialComponents.Light.DarkActionBar.Bridge but then the MaterialButtonToggleGroup is completely gone, does not show anything on the view. It does work when I remove the .Bridge. How to correctly use MaterialButtonToggleGroup without inheriting from a Material Components theme?
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar.Bridge">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="borderlessButtonStyle">#style/Widget.App.Button.TextButton</item>
<item name="materialButtonOutlinedStyle">#style/Widget.App.Button.OutlinedButton</item>
<item name="materialButtonStyle">#style/Widget.App.Button</item>
</style>
<style name="Widget.App.Button.TextButton" parent="Widget.MaterialComponents.Button.TextButton">
<item name="materialThemeOverlay">#style/ThemeOverlay.App.Button.TextButton</item>
<item name="android:textAppearance">#style/TextAppearance.App.Button</item>
<item name="shapeAppearance">#style/ShapeAppearance.App.SmallComponent</item>
</style>
<style name="Widget.App.Button.OutlinedButton" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="materialThemeOverlay">#style/ThemeOverlay.App.Button.TextButton</item>
<item name="android:textAppearance">#style/TextAppearance.App.Button</item>
<item name="shapeAppearance">#style/ShapeAppearance.App.SmallComponent</item>
</style>
<style name="Widget.App.Button" parent="Widget.MaterialComponents.Button">
<item name="materialThemeOverlay">#style/ThemeOverlay.App.Button</item>
<item name="android:textAppearance">#style/TextAppearance.App.Button</item>
<item name="shapeAppearance">#style/ShapeAppearance.App.SmallComponent</item>
</style>
<style name="ThemeOverlay.App.Button.TextButton" parent="">
<item name="colorPrimary">#color/colorPrimary</item>
</style>
<style name="ThemeOverlay.App.Button" parent="">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorOnPrimary">#ffffff</item>
</style>
<style name="TextAppearance.App.Button" parent="TextAppearance.MaterialComponents.Button">
<item name="fontFamily">serif</item>
<item name="android:fontFamily">serif</item>
</style>
<style name="ShapeAppearance.App.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">cut</item>
<item name="cornerSize">4dp</item>
</style>
</resources>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="#+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
style="#style/Widget.App.Button.OutlinedButton"
/>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
style="#style/Widget.App.Button.OutlinedButton"
/>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
style="#style/Widget.App.Button.OutlinedButton"
/>
</com.google.android.material.button.MaterialButtonToggleGroup>
</LinearLayout>
I overlooked that the error log said that the buttons inside MaterialButtonToggleGroup must be MaterialButton. When not inheriting Material Components theme, I have to explicitly use MaterialButton class instead of Button class.

Material Design and appcompat not working on older API versions

I am using appcompat v7 (23.1.1) for a MaterialDesign backward compability. On a API 21 device it looks nice. On older API versions nothing of my styles is affecting. Why?
Result in API 21 (goal):
Result in API 17 (bad):
Here is my style.xml inside values folder:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<!-- customize the color palette -->
<item name="android:colorPrimary">#color/teal200</item>
<item name="android:colorPrimaryDark">#color/teal500</item>
<item name="android:colorAccent">#color/material_green_A200</item>
<item name="android:statusBarColor">#color/teal500</item>
<item name="android:navigationBarColor">#color/teal500</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:colorButtonNormal">#color/button</item>
<item name="colorControlNormal">#color/deeporange300</item>
<item name="colorControlActivated">#color/deeporange500</item>
<item name="colorControlHighlight">#color/material_green_A200</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are specific to a particular API-level befor 21 can go here. -->
</style>
Here is the styles.xml inside values-v21 folder:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppBaseTheme">
<!-- Customize your theme using Material Design here. -->
<item name="android:buttonStyle">#style/button</item>
<item name="android:buttonStyleToggle">#style/togglebutton</item>
</style>
<style name="button" parent="#android:style/Widget.Material.Button">
<item name="android:textColor">#color/buttontextcolor</item>
</style>
<style name="togglebutton" parent="#android:style/Widget.Material.Button.Toggle">
<item name="android:textColor">#color/buttontextcolor</item>
</style>
</resources>
And here is the layout file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background"
tools:context="com.skymedium.theblowdryer.MainActivity"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/menue"
android:id="#+id/menue" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_vertical"
android:id="#+id/row1" >
<Button
android:id="#+id/tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/jukebox" />
<RelativeLayout
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0.5"
android:id="#+id/subrow" >
<ImageView
android:id="#+id/tooltip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_alignParentRight="true"
android:scaleType="fitCenter"
android:src="#drawable/abc_ab_share_pack_holo_dark" />
</RelativeLayout>
</LinearLayout>/
<LinearLayout
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="#+id/row2" >
<ToggleButton
android:id="#+id/onoff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:layout_marginRight="5dp"
android:layout_weight="0.7" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="0.3" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/swipearea" >
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_gravity="top"
android:src="#drawable/abc_ab_share_pack_holo_dark" />
</LinearLayout>
</LinearLayout>
I tried to set <item name="colorButtonNormal">#color/button_color</item>
It doesnt work too on older APIs.
Thanks in advance!
You have it backwards. Let me explain,
styles.xml
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<!-- customize the color palette -->
<!--Notice!!! No "android" prefix!-->
<item name="colorPrimary">#color/teal200</item>
<item name="colorPrimaryDark">#color/teal500</item>
<item name="colorAccent">#color/material_green_A200</item>
<item name="android:statusBarColor">#color/teal500</item>
<item name="android:navigationBarColor">#color/teal500</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:colorButtonNormal">#color/button</item>
<item name="colorControlNormal">#color/deeporange300</item>
<item name="colorControlActivated">#color/deeporange500</item>
<item name="colorControlHighlight">#color/material_green_A200</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are specific to a particular API-level befor 21 can go here. -->
</style>
styles-v21
<resources>
<style name="AppTheme" parent="AppBaseTheme">
<!-- Customize your theme using Material Design here. -->
<!--Be sure to define your colors here as well! but this time use "android:"-->
<item name="android:colorPrimary">#color/teal200</item>
<item name="android:colorPrimaryDark">#color/teal500</item>
<item name="android:colorAccent">#color/material_green_A200</item>
<item name="android:buttonStyle">#style/button</item>
<item name="android:buttonStyleToggle">#style/togglebutton</item>
</style>
<style name="button" parent="#android:style/Widget.Material.Button">
<item name="android:textColor">#color/buttontextcolor</item>
</style>
<style name="togglebutton" parent="#android:style/Widget.Material.Button.Toggle">
<item name="android:textColor">#color/buttontextcolor</item>
</style>
</resources>
styles.xml for < API 21 should not use the "android" prefix for your colors.
in styles.xml v-21 define your colors WITH the android prefix. The XML above should work!

How to apply style button in Android?

I can never apply the style of the Facebook API in myself (Login button and share), I put in "theme" and insert the code styles.xml. The design appears but is invisible, how do I apply correctly?
sorry if it's a stupid question
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.morais.daniela.doctorquiz.AutenticationActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/xxxhdpi"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button4"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="45dp"
android:theme="#style/com_facebook_loginview_default_style" />
</RelativeLayout>
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<style name="FullscreenTheme" parent="android:Theme.NoTitleBar.Fullscreen">
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">#style/ButtonBar</item>
<item name="metaButtonBarButtonStyle">#style/ButtonBarButton</item>
</style>
<style name="RatingBar">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="SRB_size">50sp</item>
</style>
<!-- Backward-compatible version of ?android:attr/buttonBarStyle -->
<style name="ButtonBar">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingRight">2dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:background">#android:drawable/bottom_bar</item>
</style>
<style name="com_facebook_loginview_default_style" parent="com_facebook_button">
<item name="android:drawableLeft">#drawable/com_facebook_button_icon</item>
</style>
<!-- Backward-compatible version of ?android:attr/buttonBarButtonStyle -->
<style name="ButtonBarButton" />
</resources>

Property "android:textSize" not applied when in custom style

I have following layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10sp"
android:paddingBottom="10sp">
<ImageView
android:id="#+id/newsImage"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:contentDescription="#string/hello_world"
android:src="#drawable/ic_program_blue" />
<RelativeLayout
android:id="#+id/textLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/newsImage">
<TextView
android:id="#+id/titleText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world"
style="#style/newsListItemTitle" />
<TextView
android:id="#+id/shortText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/titleText"
android:text="#string/hello_world"
style="#style/newsListItemShort" />
</RelativeLayout>
</RelativeLayout>
And this style definition:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="#android:style/Theme.Holo.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!-- NAVIGATION DRAWER -->
<!-- Items -->
<style name="navDrawerItem">
<item name="android:minHeight">48dp</item>
<item name="android:textSize">22sp</item>
<item name="android:textColor">#686868</item>
<item name="android:paddingRight">40dp</item>
<item name="android:gravity">center_vertical</item>
</style>
<!-- NEWS -->
<!-- Item title -->
<style name="newsListItemTitle">
<item name="android:singleLine">true</item>
<item name="android:background">#66ffffff</item>
<item name="android:paddingTop">10dp</item>
<item name="android:paddingLeft">5dp</item>
<item name="android:textColor">#000000</item>
<item name="android:textSize">23sp</item>
</style>
<!-- Item short -->
<style name="newsListItemShort">
<item name="android:singleLine">true</item>
<item name="android:background">#66ffffff</item>
<item name="android:paddingLeft">5dp</item>
<item name="android:paddingBottom">10dp</item>
<item name="android:textColor">#686868</item>
<item name="android:textSize">15sp</item>
</style>
</resources>
Everything gets applied to the TextViews, except the "textSize". No text does appear in the configured textSize height. Any idea, why this is not working?
No compile errors.
When I apply the property "textSize" with the TextView directly everythink works fine.
Thanks
I made the corrections to the wrong "styles.xml" file. I have a styles file for API larger than 16. And this file gets used. But I edited the standard "styles.xml".
Try to add in the below folder structure:
res/values/dimens.xml
res/values-small/dimens.xml
res/values-normal/dimens.xml
res/values-xlarge/dimens.xml
Example:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">18sp</dimen>
</resources>

Categories

Resources