چرا فونت به جای گرفتن از type ، از theme.xml گرفته می شود؟

پرسیده شده
فعالیت 1086 روز پیش
دیده شده 691 بار
1

سلام وقت به خیر
من برای textview خودم android:textAppearance="?textAppearanceHeadline۶" رو ست کردم و در فایل theme  هم علاوه بر اتریبیوت های مربوط به type ، اتریبیوت <item name="fontFamily">@font/primary_regular</item> 
رو هم قرار دادم.
بعد توی headline۶ مربوط به فایل type هم ایتم های زیر رو قرار دادم:
<item name="fontFamily">@font/primary_bold</item>
<item name="android:fontFamily">@font/primary_bold</item>
<item name="android:textSize">۱۶sp</item>
<item name="android:textColor">@color/black</item>
اما به جای اینکه فونت رو primary_bold در نظر بگیره، primary_regular ای که توی theme رو داره ست می کنه!!!
دقیقا مشابه عملکرد استاد رفتم جلو و جالب این جاست که وقتی اندازه ی فونت رو عوض می کنم،درست عوض می شه(مثلا از ۱۶ به ۲۴ تغییر بدم،اندازه متن بزرگ تر می شه) اما راجع به فونت،هیچ تغییری رو اعمال نمی کنه و فقط از توی theme  می خونه.
ممنون می شم راهنمایی بفرمایید.
 

فایل پیوست

حسین عاشوری
حسین عاشوری

18 اردیبهشت 00

0
حذف شده

سلام وقت بخیر

 

احتمالا جایی رو به اشتباه وارد کردید من در هر حال براتون کدهای مربوطه قرار میدم

 

فایل styles.xml

<resources>
<style name="MyBottomNavigationView" parent="Widget.MaterialComponents.BottomNavigationView">
<item name="itemIconTint">@color/bottom_navigation_item_color</item>
<item name="itemTextColor">@color/bottom_navigation_item_color</item>
<item name="itemRippleColor">@color/bottom_navigation_ripple_color</item>
<item name="itemTextAppearanceActive">@style/ActiveItemBottomNavigationTextAppearance</item>
</style>
<style name="ActiveItemBottomNavigationTextAppearance" parent="TextAppearance.MyTheme.Caption">
<item name="fontFamily">@font/primary_bold</item>
<item name="android:fontFamily">@font/primary_bold</item>
</style>
<style name="Theme.Nike.AuthTheme.Button" parent="Theme.Nike.AuthTheme">
<item name="backgroundTint">?colorOnBackground</item>
<item name="android:textColor">@color/black</item>
<item name="cornerRadius">8dp</item>
<item name="android:fontFamily">@font/primary_bold</item>
</style>
<style name="Theme.Nike.AuthTheme.EditText" parent="Theme.Nike.AuthTheme">
<item name="android:background">@drawable/background_auth_et</item>
<item name="android:textColorHint">#48ffffff</item>
<item name="android:textColor">?colorOnBackground</item>
<item name="android:textSize">16sp</item>
<item name="android:minHeight">48dp</item>
<item name="android:paddingEnd">16dp</item>
<item name="android:paddingStart">16dp</item>
</style>
</resources>

themes.xml

<resources xmlns:tools="http://schemas.android.com/tools">
<!--  Base application theme.  -->
<style name="Theme.NikeStore" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!--  Primary brand color.  -->
<item name="colorPrimary">@color/blue</item>
<item name="colorOnPrimary">@color/white</item>
<!--  Secondary brand color.  -->
<item name="colorSecondary">@color/black</item>
<item name="colorOnSecondary">@color/white</item>
<!--  Status bar color.  -->
<item name="android:statusBarColor" tools:targetApi="l">@color/gray</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
<item name="fontFamily">@font/primary_regular</item>
<item name="windowBackgroundColorSub">#f5f5f5</item>
<!-- Material type attributes -->
<item name="textAppearanceHeadline1">@style/TextAppearance.MyTheme.Headline1</item>
<item name="textAppearanceHeadline2">@style/TextAppearance.MyTheme.Headline2</item>
<item name="textAppearanceHeadline3">@style/TextAppearance.MyTheme.Headline3</item>
<item name="textAppearanceHeadline4">@style/TextAppearance.MyTheme.Headline4</item>
<item name="textAppearanceHeadline5">@style/TextAppearance.MyTheme.Headline5</item>
<item name="textAppearanceHeadline6">@style/TextAppearance.MyTheme.Headline6</item>
<item name="textAppearanceSubtitle1">@style/TextAppearance.MyTheme.Subtitle1</item>
<item name="textAppearanceSubtitle2">@style/TextAppearance.MyTheme.Subtitle2</item>
<item name="textAppearanceBody1">@style/TextAppearance.MyTheme.Body1</item>
<item name="textAppearanceBody2">@style/TextAppearance.MyTheme.Body2</item>
<item name="textAppearanceButton">@style/TextAppearance.MyTheme.Button</item>
<item name="textAppearanceCaption">@style/TextAppearance.MyTheme.Caption</item>
<item name="textAppearanceOverline">@style/TextAppearance.MyTheme.Overline</item>
<!--  Customize your theme here.  -->
<item name="bottomNavigationStyle">@style/MyBottomNavigationView</item>
<item name="appBarLayoutStyle">
@style/Widget.MaterialComponents.AppBarLayout.Surface
</item>
<item name="dividerColor">@color/gray</item>
<item name="android:textColorSecondary">@color/darkGray</item>
<item name="android:lineSpacingExtra">6dp</item>
<item name="android:includeFontPadding">false</item>
</style>
<style name="Theme.Nike.AuthTheme" parent="Theme.NikeStore">
<item name="android:statusBarColor" tools:targetApi="lollipop">@color/black</item>
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
<item name="android:windowBackground">@color/black</item>
<item name="colorOnBackground">@color/white</item>
<item name="colorOnSurface">@color/white</item>
<item name="materialButtonStyle">@style/Theme.Nike.AuthTheme.Button</item>
</style>
</resources>

type.xml

<resources>
<!-- Typography -->
<!--
Material’s type system supports 13 categories that, when combined, form the typescale. 
-->
<!--
This typescale is evident in the variety of text styles and sizes that appear on screen, 
-->
<!--
ranging from body copy to buttons. Type appears across the UI, in places such as in 
-->
<!-- components and on surfaces. -->
<!--
These styles should be used throughout your app when creating text views so all your 
-->
<!--
text is consistently styled and easily updated if design or product needs change. Each 
-->
<!--
style in the type scale can be customized by defining a style and overriding that 
-->
<!--
style's Material Theme attribute (?textAppearanceHeadline1, ?textAppearanceBody2, etc.) 
-->
<!--
in your app's theme. In this project, type attributes have already been overridden in 
-->
<!--
themes.xml and are set to the styles in this file, type.xml. These ?textAppearance* 
-->
<!--
theme attributes should be used in your layouts to set a TextView’s appearance instead 
-->
<!--
of fully qualified style references and in favor of manually setting text properties.
-->
<!--
Type on Android is themed by defining a custom TextAppearance for each type scale style. 
-->
<!--
Use standard TextAppearance attributes such as textSize, textColor, fontFamily, 
-->
<!--
letterSpacing, etc. to define a custom appearance for each and see how they are 
-->
<!-- applied globally across your app. -->
<style name="TextAppearance.MyTheme.Headline1" parent="TextAppearance.MaterialComponents.Headline1">
<!-- Your custom type style here -->
<item name="android:textColor">?colorPrimary</item>
</style>
<style name="TextAppearance.MyTheme.Headline2" parent="TextAppearance.MaterialComponents.Headline2">
<!-- Your custom type style here -->
</style>
<style name="TextAppearance.MyTheme.Headline3" parent="TextAppearance.MaterialComponents.Headline3">
<!-- Your custom type style here -->
</style>
<style name="TextAppearance.MyTheme.Headline4" parent="TextAppearance.MaterialComponents.Headline4">
<!-- Your custom type style here -->
</style>
<style name="TextAppearance.MyTheme.Headline5" parent="TextAppearance.MaterialComponents.Headline5">
<!-- Your custom type style here -->
<item name="android:textSize">18sp</item>
<item name="android:textColor">?colorOnBackground</item>
</style>
<style name="TextAppearance.MyTheme.Headline6" parent="TextAppearance.MaterialComponents.Headline6">
<!-- Your custom type style here -->
<item name="fontFamily">@font/primary_bold</item>
<item name="android:fontFamily">@font/primary_bold</item>
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/black</item>
</style>
<style name="TextAppearance.MyTheme.Subtitle1" parent="TextAppearance.MaterialComponents.Subtitle1">
<!-- Your custom type style here -->
</style>
<style name="TextAppearance.MyTheme.Subtitle2" parent="TextAppearance.MaterialComponents.Subtitle2">
<!-- Your custom type style here -->
</style>
<style name="TextAppearance.MyTheme.Body1" parent="TextAppearance.MaterialComponents.Body1">
<!-- Your custom type style here -->
<item name="android:textColor">?colorOnSurface</item>
<item name="android:textSize">14sp</item>
</style>
<style name="TextAppearance.MyTheme.Body2" parent="TextAppearance.MaterialComponents.Body2">
<!-- Your custom type style here -->
<item name="android:textColor">?colorOnSurface</item>
<item name="android:textSize">12sp</item>
</style>
<style name="TextAppearance.MyTheme.Button" parent="TextAppearance.MaterialComponents.Button">
<!-- Your custom type style here -->
</style>
<style name="TextAppearance.MyTheme.Caption" parent="TextAppearance.MaterialComponents.Caption">
<!-- Your custom type style here -->
</style>
<style name="TextAppearance.MyTheme.Overline" parent="TextAppearance.MaterialComponents.Overline">
<!-- Your custom type style here -->
</style>
</resources>
فایل پیوست

پوریا شفیعی

توسط

پوریا شفیعی

18 اردیبهشت 00

1
حذف شده

ممنون از توجه شما
من چک کردم و مشابه بود. عکس مربوط به کدم رو می فرستم براتون. ممنون می شم شما هم ملاحظه کنید.
اینکه می ره از فایل type.xml و از بخش headline6 اون textAppearance رو می گیره، مطمئن هستم. چون اندازه فونت داره ست می شه.
اما فونت رو از اون بخش نمی گیره و از theme.xml داره می گیره.
ممنون می شم متوجه اشتباهم شدید، بفرمایید.

فایل پیوست

حسین عاشوری

توسط

حسین عاشوری

18 اردیبهشت 00

حذف شده
مشکلی ندیدم پیشنهاد میکنم سورس مربوطه رو دانلود بفرمایید و با کد خودتون مطابقت بدین چون در حال حاظر من به سورس شما رو در اختیار ندارم
پوریا شفیعی

20 اردیبهشت 00