How to inherit style from layout in Android
I have tried inheriting styles in android layout xml. It now looks like this:
layout.xml:
<RelativeLayout
android:id="@id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
style="@style/AppTheme.ButtonLayout">
<TextView
android:id="@id/btn_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AppTheme.ButtonLayout.TextView" />
</RelativeLayout>
styles.xml:
<style name="AppTheme.ButtonLayout">
<item name="android:textViewStyle">@style/AppTheme.ButtonLayout.TextView</item>
</style>
<style name="AppTheme.ButtonLayout.TextView" parent="android:Widget.Holo.Light.TextView">
<item name="android:textColor">@android:color/white</item>
</style>
I want to get rid of the attribute style
from the TextView, but it must inherit the look and feel from the RelativeLayout. Is it possible?
Edit: I want this TextView to have this style only in a RelativeLayout with a type @style/AppTheme.ButtonLayout
. When inside a layout without this style, it should look like the default Android TextView.
source to share
you can inherit styles in android layout xml from example style.xml with following ..
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.prj.name"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity> </activity>
</application>
</manifest>
themes_apptheme.xml you can call the ad name from the parent name
<?xml version="1.0" encoding="utf-8"?>
<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="@style/_AppTheme" />
<style name="_AppTheme" parent="android:Theme.Holo.Light">
<item name="android:textColorHighlight">#99ff6d00</item>
<item name="android:textViewStyle">@style/TextViewAppTheme</item>
</style>
styles_apptheme.xml // what you want to create, you can call from the drop-down folder with png-format
<style name="TextViewAppTheme" parent="android:Widget.Holo.Light.TextView">
<item name="android:background">@drawable/apptheme_text_holo_light</item>
</style>
style.xml
<style name="Widget.Holo.Light.TextView" parent="Widget.TextView">
<item name="android:textcolor"> .........</item>
</style>
<style name="Widget.TextView">
<item name="android:textAppearance">?android:attr/textAppearanceMediumInverse</item>
<item name="android:gravity">center_vertical</item>
</style>
source to share