Skip to content

Instantly share code, notes, and snippets.

@Muyangmin
Forked from romannurik/AndroidManifest.xml
Created March 14, 2017 07:45
Show Gist options
  • Select an option

  • Save Muyangmin/7b53a3d9efa4e1214217fded9d5cc42f to your computer and use it in GitHub Desktop.

Select an option

Save Muyangmin/7b53a3d9efa4e1214217fded9d5cc42f to your computer and use it in GitHub Desktop.

Revisions

  1. @romannurik romannurik revised this gist Oct 17, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions res_values_styles_attrs.xml
    Original file line number Diff line number Diff line change
    @@ -14,12 +14,12 @@
    change the default button style, you can instead
    override the android:buttonStyle attribute. -->
    <style name="AppTheme" parent="android:Theme.Holo">
    <item name="myButtonStyle">@style/MyButtonStyle</item>
    <item name="myButtonStyle">@style/MyButton</item>
    </style>

    <!-- Define the custom button style itself. Make sure
    to inherit from an existing button style. -->
    <style name="MyButtonStyle" parent="android:Widget.Holo.Button">
    <style name="MyButton" parent="android:Widget.Holo.Button">
    <item name="android:textColor">#f00</item>
    </style>

  2. @romannurik romannurik created this gist Oct 17, 2013.
    8 changes: 8 additions & 0 deletions AndroidManifest.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    <manifest ...>
    ...
    <!-- Make sure your app (or individual activity) uses the
    theme with the custom attribute defined. -->
    <application android:theme="@style/AppTheme" ...>
    ...
    </application>
    </manifest>
    15 changes: 15 additions & 0 deletions MyActivity.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    public class MyActivity extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...

    // Pass in the theme attribute that'll resolve to the
    // desired button style resource. The current theme
    // must have a value set for this attribute.
    Button myButton = new Button(this, null, R.attr.myButtonStyle);
    myButton.setText("Hello world");

    ViewGroup containerView = (ViewGroup) findViewById(R.id.container);
    containerView.addView(myButton);
    }
    }
    26 changes: 26 additions & 0 deletions res_values_styles_attrs.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    <!-- The convention is to put the <style> elements below
    in res/values/styles.xml and <declare-styleable> in
    res/values/attrs.xml. -->
    <resources>

    <!-- First declare a custom theme attribute that'll
    reference a style resource. -->
    <declare-styleable name="AppTheme">
    <attr name="myButtonStyle" format="reference" />
    </declare-styleable>

    <!-- Provide a style resource as the value for the
    theme attribute. As a side note, if you want to
    change the default button style, you can instead
    override the android:buttonStyle attribute. -->
    <style name="AppTheme" parent="android:Theme.Holo">
    <item name="myButtonStyle">@style/MyButtonStyle</item>
    </style>

    <!-- Define the custom button style itself. Make sure
    to inherit from an existing button style. -->
    <style name="MyButtonStyle" parent="android:Widget.Holo.Button">
    <item name="android:textColor">#f00</item>
    </style>

    </resources>