gpt4 book ai didi

android - Android布局中如何继承样式

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:44:50 26 4
gpt4 key购买 nike

我尝试继承 Android 布局 xml 中的样式。现在看起来像:

布局.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>

样式.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 的 style 属性,但它应该继承 RelativeLayout 的外观。可能吗?

编辑:我希望此 TextView 在具有 @style/AppTheme.ButtonLayout 样式的 RelativeLayout 中具有此类样式。当它在没有这种样式的内部布局时,它应该看起来像默认的 Android TextView。

最佳答案

您可以从以下 style.xml 示例继承 Android 布局 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 你可以从父名称中调用declare 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//你想设计什么你可以从drawable文件夹调用png格式

 <style name="TextViewAppTheme" parent="android:Widget.Holo.Light.TextView">
<item name="android:background">@drawable/apptheme_text_holo_light</item>
</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 - Android布局中如何继承样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25640075/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com