如何继承风格在Android的布局 [英] How to inherit style in layout in Android

查看:268
本文介绍了如何继承风格在Android的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力,在继承Android的布局XML风格。
现在,它看起来像:

I've tried to inherit styles in Android layout xml. Now it looks like:

layout.xml:

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:

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>

我想摆脱从TextView的风格属性,但它应该继承RelativeLayout的外观。这可能吗?

I want to get rid of style attribute from the TextView, but it should inherit appearance from RelativeLayout. Is it possible?

编辑:我想这个TextView中有这样风格的中的RelativeLayout与 @风格/ AppTheme.ButtonLayout 的风格。当它里面没有布局这种风格,它应该看起来像默认的Andr​​oid TextView的。

I want this TextView to have such style only within RelativeLayout with @style/AppTheme.ButtonLayout style. When it is inside layout without this style, it should looks like default Android TextView.

推荐答案

您可以在以下继承从style.xml例如Android的布局XML风格。

you can inherit styles in Android layout xml from style.xml example at following..

AndroidManifest.xml中

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你可以调用来自父系的名称申报名称

themes_apptheme.xml you can call declare name from 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
//你想设计可以从绘制文件夹中调用与PNG格式是什么

styles_apptheme.xml //what you want to design you can call from drawable 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.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>

这篇关于如何继承风格在Android的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆