-1

i'm generation a Textview programmatically. I'm using a layout file to inflate the TextView. The problem is, that not all items of the style are applied to the TextView (android:layout_margin) what is my fault?

this is the style I'm defined in AppTheme

<style name="Theme.CampApp.TextItem" parent="TextAppearance.Material3.BodyMedium">
    <item name="android:textSize">32dp</item>
    <item name="android:background">@drawable/rounded</item>
    <item name="android:padding">@dimen/textItemPadding</item>
    <item name="android:layout_margin">32dp</item>
</style>

this is my layout file

<com.google.android.material.textview.MaterialTextView
    xmlns:android="http://schemas.android.com/apk/rses/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/Theme.CampApp.TextItem">

</com.google.android.material.textview.MaterialTextView>

this is the Code , generating the TextView

 val textItem = layoutInflater.inflate(R.layout.text_view_item_layout ,null) as TextView

    textItem.setTextAppearance(R.style.Theme_CampApp_TextItem)
    val params = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT ,RelativeLayout.LayoutParams.WRAP_CONTENT )
    textItem.layoutParams = params
    textItem!!.id = View.generateViewId()
Peter
  • 29
  • 3

1 Answers1

0

Try this:

textView.setTextAppearance(this, R.style.MyTextStyle);

commandiron
  • 1,019
  • 1
  • 9
  • 25
Mokhtar Abdelhalim
  • 232
  • 1
  • 3
  • 9