title: Android: Padding specified in styles.xml not showing in programmatically added TextView?
body: <p>I am programmatically adding a <code>TextView</code> to my app's UI and making it have a small padding, based on a configuration in <code>styles.xml</code>. However, when I run my app, the <code>TextView</code> has no padding:</p>
  <p><a href="https://i.stack.imgur.com/6mMnd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6mMnd.png" alt="enter image description here" /></a></p>
  <p>This seems strange, considering that I believe I have defined the padding in my <code>styles.xml</code> configuration and set it programmatically in my <code>MainActivity.java</code> correctly. Below is my code:</p>
  <p><strong>styles.xml</strong>:</p>
  <pre><code>&lt;resources&gt;
      &lt;!-- Base application theme. --&gt;
      &lt;style name=&quot;AppTheme&quot; parent=&quot;Theme.AppCompat.Light.DarkActionBar&quot;&gt;
          &lt;!-- Customize your theme here. --&gt;
          &lt;item name=&quot;colorPrimary&quot;&gt;@color/colorPrimary&lt;/item&gt;
          &lt;item name=&quot;colorPrimaryDark&quot;&gt;@color/colorPrimaryDark&lt;/item&gt;
          &lt;item name=&quot;colorAccent&quot;&gt;@color/colorAccent&lt;/item&gt;
      &lt;/style&gt;
  
      &lt;!-- Message alerting the user that the app has not finished scraping the schedule --&gt;
      &lt;style name=&quot;NotDoneScrapingMsg&quot; parent=&quot;@android:style/Widget.TextView&quot;&gt;
          &lt;item name=&quot;android:textSize&quot;&gt;16sp&lt;/item&gt;
          &lt;item name=&quot;android:textColor&quot;&gt;#000000&lt;/item&gt;
          &lt;item name=&quot;android:paddingLeft&quot;&gt;7dp&lt;/item&gt;
      &lt;/style&gt;
  &lt;/resources&gt;
  </code></pre>
  <p><strong>activity_main.xml</strong>:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.MainActivity&quot;&gt;
  
      &lt;LinearLayout
          android:id=&quot;@+id/baseLayout&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:orientation=&quot;vertical&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p><strong>MainActivity.kt</strong>:</p>
  <pre><code>package com.example.addtextviewwithpadding
  
  import androidx.appcompat.app.AppCompatActivity
  import android.os.Bundle
  import android.widget.LinearLayout
  import android.widget.TextView
  import androidx.core.widget.TextViewCompat
  
  class MainActivity : AppCompatActivity() {
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          val baseLayout: LinearLayout = findViewById&lt;LinearLayout&gt;(R.id.baseLayout)
  
          // Create and add a TextView telling the user that the app is still retrieving the schedule
          val notDoneScrapingMsg = TextView(applicationContext)
          notDoneScrapingMsg.text = &quot;Test Padding&quot;
          //valueTV.id = 5
          notDoneScrapingMsg.layoutParams = LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.MATCH_PARENT,
              LinearLayout.LayoutParams.WRAP_CONTENT
          )
          TextViewCompat.setTextAppearance(notDoneScrapingMsg, R.style.NotDoneScrapingMsg)
  
          baseLayout.addView(notDoneScrapingMsg)
      }
  }
  </code></pre>