Skip to content

Instantly share code, notes, and snippets.

@GabriellCosta
Created January 22, 2019 18:02
Show Gist options
  • Save GabriellCosta/e36416bd134a25834b7cbf10e4e8e6d6 to your computer and use it in GitHub Desktop.
Save GabriellCosta/e36416bd134a25834b7cbf10e4e8e6d6 to your computer and use it in GitHub Desktop.
String Attr
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="sample_attr_value" format="string"/>
</resources>
package com.gabrielcosta.attrsample
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.TypedValue
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val typedValue = TypedValue()
val resolveAttribute = theme.resolveAttribute(R.attr.sample_attr_value, typedValue, true)
txt_sampleText.text = typedValue.string
}
}
<resources>
<string name="app_name">AttrSample</string>
<string name="first_screen" >First Screen %s</string>
<string name="second_screen" >Second Screen</string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.First">
<item name="sample_attr_value">@string/first_screen</item>
</style>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment