android-styles 相关问题

样式是一组属性,用于指定视图或窗口的外观和格式

为什么 Android Studio 在我的项目中使用自定义样式时出现问题?

在布局中引用我的项目自定义样式之一时,我都会收到有关无关输入的语法错误。语法错误 样式仍然正确应用于布局和项目

回答 1 投票 0

在 Android Studio 中哪里可以找到 styles.xml 文件?

我有一个非常简单的应用程序,它运行一个 html 文件。我真的很想改变状态栏的颜色,因为黑色的标准顶部和底部对于 p 的调色板来说太糟糕了......

回答 4 投票 0

获取Android系统强调色(Android 10系统强调色)

这个问题应该很简单,但我没有找到答案。我有一个带有可选口音的应用程序,我正在尝试添加一个选项来使用 android 系统口音(像 Lawnchair 这样的应用程序有这样一个

回答 4 投票 0


在 Android 中手动输入日期时,MaterialDatePicker 文本颜色存在问题

我面临的问题是无法在对话框中手动输入日期时更改白色。我该如何改变这个颜色? 我尝试过这个但仍然不起作用。 <p>我面临的问题是无法在对话框中手动输入日期时更改白色。我该如何改变这个颜色? <a href="https://i.stack.imgur.com/n1SGJ.png" target="_blank"><img src="https://cdn.txt58.com/i/AWkuc3RhY2suaW1ndXIuY29tL24xU0dKLnBuZw==" alt=""/></a></p> <p>我尝试了这个,但仍然不起作用。</p> <pre><code>&lt;style name=&#34;MaterialCalendarTheme&#34; parent=&#34;ThemeOverlay.MaterialComponents.MaterialCalendar&#34;&gt; &lt;!-- Header panel --&gt; &lt;item name=&#34;materialCalendarHeaderLayout&#34;&gt;@style/MaterialCalendar.HeaderLayout1&lt;/item&gt; &lt;!-- Buttons --&gt; &lt;item name=&#34;buttonBarPositiveButtonStyle&#34;&gt;@style/TextButton.Dialog1&lt;/item&gt; &lt;item name=&#34;buttonBarNegativeButtonStyle&#34;&gt;@style/TextButton.Dialog1&lt;/item&gt; &lt;/style&gt; </code></pre> <pre><code>&lt;style name=&#34;MaterialCalendar.HeaderLayout1&#34; parent=&#34;Widget.MaterialComponents.MaterialCalendar.HeaderLayout&#34;&gt; &lt;!--&lt;item name=&#34;android:background&#34;&gt;?attr/colorPrimary&lt;/item&gt;--&gt; &lt;item name=&#34;android:background&#34;&gt;@color/colorPrimary&lt;/item&gt; &lt;item name=&#34;android:headerMonthTextAppearance&#34;&gt;@color/black&lt;/item&gt; &lt;/style&gt; &lt;style name=&#34;TextButton.Dialog1&#34; parent=&#34;Widget.MaterialComponents.Button.TextButton.Dialog&#34;&gt; &lt;item name=&#34;android:textColor&#34;&gt;@color/black&lt;/item&gt; &lt;/style&gt; </code></pre> </question> <answer tick="false" vote="0"> <p>如果您使用 <strong>Android Studio</strong> ,请转到 Layout 并单击您要布局的布局,然后打开 Design 并查找 textColor ,然后您就可以进行 sumach 更改,或者单击 Code ,然后在 EditText Datum 中写入 <pre><code>android:textColor=&#34;#000000&#34;</code></pre> 。试试这个并告诉我结果。</p> </answer> </body></html>

回答 0 投票 0

如何在 Android XML 中为文本添加下划线?

如何在 XML 文件中的文本下划线?我在 textStyle 中找不到选项。

回答 12 投票 0

自 Android Studio 4.1 起,Android 后台 Drawable 无法在按钮中工作

我发现从 Android Studio 4.1 开始,我无法通过在其 android:background 上设置颜色来更改 Button 的背景颜色,只是没有效果。并且自定义 Drawable 也无法正常工作。 我的

回答 6 投票 0

更改TextInputLayout的下划线颜色和浮动提示颜色

我在 TextInputLayout 主题中使用上述属性,使 TextInputLayout 激活时的下划线颜色为绿色。 #27e905...

回答 5 投票 0

我缺少哪种样式来更改 AlertDialog 按钮颜色?与 MaterialAlertDialog 配合使用效果良好

编辑:我应该提到我已经阅读了很多有关 AlertDialog 样式的答案,并尝试了我能找到的所有建议,所以请不要使其重复。 我正在测试一个示例类。 ...

回答 1 投票 0

当primaryDark为白色时更改状态栏文本颜色

我正在尝试重现 Google 日历应用程序的行为: 但我还没有找到改变状态文本颜色的方法。如果我将 colorPrimaryDark 设置为白色,我看不到图标 nei...

回答 15 投票 0

以编程方式设置 android:windowIsTranslucent

按照本教程http://cases.azoft.com/android-tutorial-floating-activity/后,我能够创建浮动活动 但是,为此,我必须在 styles.xml 中添加这一行: 按照本教程后,我能够创建浮动活动http://cases.azoft.com/android-tutorial-floating-activity/ 但是,为此,我必须在 styles.xml 中添加这一行: <item name="android:windowIsTranslucent">true</item> 仅使用 Android/Java 代码是否可以达到相同的效果? (例如在 Activity.onAttachedToWindow() 左右...) 预先感谢您的帮助。 [编辑 01] styles.xml 不得更改(而且我不应该知道其中有什么......)。但出于测试目的,我使用默认的: <resources> <style name="AppBaseTheme" parent="Theme.AppCompat.Light"> </style> <style name="AppTheme" parent="AppBaseTheme"> </style> </resources> [编辑02]Resources.Theme.applyStyle()似乎做了我想做的事情(根据API描述:“将新属性值放入主题”)。 所以我创建了以下custom_style.xml: <resources> <style name="MyCustomStyle" > <item name="android:windowIsTranslucent">true</item> </style> </resources> 然后,在onAttachedToWindow(),我打电话: getTheme().applyStyle(R.style.MyCustomStyle, true); 但是没有任何效果... 仅使用Android/Java代码是否可以达到相同的效果? 恐怕不行。您只需在 styles.xml 内完成即可。据我所知 android:windowIsTranslucent 的值无法通过编程单独更改。 当我们调用 super.onCreate(savedInstanceState); 时,Activity 类提供了一个空的图形窗口,我们可以在其中设置内容,即视图。并将主题应用于该窗口,然后将内容加载到该视图上。 因此顺序将是, 致电super.onCreate() 设置活动主题。 设置该活动的内容视图。 例如。 styles.xml <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> <item name="android:windowBackground">@drawable/background</item> <item name="android:windowNoTitle">true</item> </style> <!-- Application theme.without title bar --> <style name="AppTheme.NoTitleBar" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> <item name="android:windowBackground">@drawable/background</item> <item name="android:windowNoTitle">true</item> </style> <!--Floating activity theme --> <style name="Theme_Translucent" parent="android:style/Theme.NoTitleBar.Fullscreen"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowFrame">@null</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:backgroundDimEnabled">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle">true</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <item name="android:windowFullscreen">true</item> </style> 然后为Floating activity设置主题,如下所示: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTheme(R.style.Theme_Translucent); // Set here setContentView(...) } 这样做 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window w = getWindow(); // in Activity's onCreate() for instance w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } Android R 出现新方法 不能说要以编程方式执行此操作..但如果您需要执行此操作,您可以像这样尝试.. 将主题添加到清单文件中的活动中,如下所示.. android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" 示例:- <activity android:name="com.example.androidhackerphonelocker.MainActivity" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 希望它能解决您的一些问题.. 也许这会有所帮助。 @Override protected void onCreate(Bundle savedInstanceState) { processSetTheme(this); getWindow().requestFeature(Window.FEATURE_NO_TITLE); getWindow().setBackgroundDrawableResource(R.color.realTranslucent); if (Build.VERSION.SDK_INT>=19){ getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } super.onCreate(savedInstanceState); <color name="realTranslucent">#00000000</color> 如果 android.app.Dialog window.setDimAmount(0f) window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) 从 API 级别 30 开始,现在有一个 setTranslucent 方法: 将活动(尤其是具有 R.attr.windowIsTranslucent 或 R.attr.windowIsFloating 属性的活动)转换为全屏不透明活动,或将其从不透明转换回半透明。 文档

回答 7 投票 0

Android Studio(我该如何修复它?)

如何将密码文本框与用户名文本框对齐以看起来像这样的设计,或者我可以做些什么来修复它? 代码 如何将密码文本框与用户名文本框对齐,使其看起来像 或者如何修复它? 代码 <EditText android:id="@+id/aduser" android:layout_width="0dp" android:layout_height="55dp" android:layout_marginEnd="32dp" android:layout_marginStart="32dp" android:layout_marginTop="16dp" android:drawableStart="@drawable/userconfig1" android:drawablePadding="16dp" android:hint="Username" android:textColorHint="#000000" android:textStyle="bold" android:textSize="18dp" android:background="@drawable/button_bg" android:ems="10" android:inputType="text" android:textColor="#000000" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/imageView2" /> <com.google.android.material.textfield.TextInputLayout android:id="@+id/adpass" android:layout_width="0dp" android:layout_height="55dp" android:layout_marginStart="32dp" android:layout_marginEnd="32dp" android:layout_marginTop="24dp" android:hint="Password" app:passwordToggleEnabled="true" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/aduser" > <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/button_bg" android:drawableStart="@drawable/baseline_info_24" android:drawablePadding="16dp" android:ems="10" android:inputType="textPassword" android:textColor="#000000" android:textColorHint="#000000" android:textSize="18dp" android:textStyle="bold" /> </com.google.android.material.textfield.TextInputLayout> 我的设计如何改进?我道歉;我是 Android Studio 的新手,目前正在测试设计。 我期望的设计是用户名和密码相等并且密码的颜色与用户名不远,并且启用显示/隐藏密码。 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".InterstitialAdsActivity"> <com.google.android.material.textfield.TextInputLayout android:id="@+id/aduserL" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginHorizontal="10dp" android:layout_marginVertical="4dp" android:hint="Username" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/aduser" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableStart="@drawable/ic_star" android:drawablePadding="16dp" android:ems="10" android:inputType="text" android:textColor="#000000" android:textColorHint="#000000" android:textSize="18dp" android:textStyle="bold" /> </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout android:id="@+id/adpass" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginHorizontal="10dp" android:layout_marginVertical="4dp" android:hint="Password" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/aduserL" app:passwordToggleEnabled="true"> <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="match_parent" android:drawableStart="@drawable/ic_star" android:drawablePadding="16dp" android:ems="10" android:inputType="textPassword" android:textColor="#000000" android:textColorHint="#000000" android:textSize="18dp" android:textStyle="bold" /> </com.google.android.material.textfield.TextInputLayout> </androidx.constraintlayout.widget.ConstraintLayout> 如果您推荐观看此视频youtubeVideo

回答 1 投票 0

警报对话框消息的自定义字体

我正在为我的自定义 AlertDialog 使用以下样式。指定的字体“myfont.tff”应用于 AlertDialog 标题和按钮,但不应用于 AlertDialog 消息。我需要什么...

回答 1 投票 0

更改EditTextPreference的标题文本颜色

如何更改以下首选项 XML 中标题和摘要的颜色: 如何更改以下首选项 XML 中 title 和 summary 的颜色: <EditTextPreference android:key="username" android:title="Your Name" android:summary="Please provide your username." /> 我在我的styles.xml中尝试过这个: <style name="SettingsTheme" parent="@style/AppBaseTheme"> <item name="android:textColorPrimary">@color/green</item> <item name="android:textColorSecondary">@color/red</item> <item name="android:textColorTertiary">@color/blue</item> </style> textColorPrimary 更改标题的颜色,但它也会更改工具栏中文本的颜色(我不想要)。 textColorSecond 似乎正确地改变了摘要的颜色。 如何在不影响工具栏文本颜色的情况下更改标题颜色? 您需要像这样显式定义 EditTextPreference 的样式: <style name="SettingsTheme" parent="@style/AppBaseTheme"> <item name="android:editTextPreferenceStyle">@style/MyStyle</item> </style> <style name="MyStyle" parent="@android:style/Preference.DialogPreference.EditTextPreference"> ... </style> 这会将您在 MyStyle 中定义的任何样式仅设置为之前 EditTextPreference 默认样式的位置。 我最近也遇到了同样的问题。刚刚找到了答案。我制作了一个自定义的 EditTextPreference 并在我的代码中执行此操作来更改标题和摘要颜色,我还尝试更改图标色调(颜色)并且它正在工作,您所需要做的就是找到您需要更改的视图并应用您的视图修改如下: class MyEditTextPreference : EditTextPreference { constructor(context: Context) : super(context) constructor(context: Context, attr : AttributeSet?) : super(context, attr) constructor(context: Context, attr: AttributeSet?, i1: Int) : super(context, attr, i1) constructor(context: Context, attr: AttributeSet?, i1: Int, i2: Int) : super(context, attr, i1, i2) override fun onBindViewHolder(holder: PreferenceViewHolder) { super.onBindViewHolder(holder) (holder.findViewById(android.R.id.title) as TextView).setTextColor(Color.WHITE) (holder.findViewById(android.R.id.icon) as PreferenceImageView).imageTintList = ColorStateList.valueOf(Color.WHITE) (holder.findViewById(android.R.id.summary) as TextView).setTextColor(ResourcesCompat.getColor(context.resources, R.color.test_color, null)) } } 在你的 xml 文件中你必须使用这个 <mypackage.MyEditTextPreference app:icon="@drawable/ic_test" app:key="testKey" app:title="@string/testString" app:useSimpleSummaryProvider="true" /> 注1: 我使用了一个简单的摘要提供程序,但您可以使用您想要的任何摘要。 注2: 这些代码是用 kotlin 编写的,但您可以简单地将它们转换为 Java。 我认为最简单的方法是子类化 EditTextPreference 并在 onCreateView() 或 onBindView() 中调整标题颜色。 public class MyEditTextPreference extends EditTextPreference { // constructors omitted @Override protected void onBindView(View view) { TextView titleView = (TextView) view.findViewById(android.R.id.title); int color = getContext().getResources().getColor(R.color.preference_title); titleView.setTextColor(color); } } 然后在您的首选项 XML 中,您将使用您的类(完全限定名称): <com.package.MyEditTextPreference android:key="username" android:title="Your Name" android:summary="Please provide your username." />

回答 3 投票 0

如何制作自定义输入pin码Android?

我在 Kotlin Android 上制作项目。我怎样才能使相同的字段和相同的输入?在我看来,创建一些编辑文本并不是一个好的决定 在此输入图像描述 输入图像描述她...

回答 1 投票 0


如何设置android操作栏选项卡的高度

基本上,我想更改操作栏中选项卡的高度。这个问题在 stackoverflow 上已经被问过好几次了,例如: ActionBar 选项卡高度 我已经尝试了大部分解决方案...

回答 2 投票 0

如何使样式从带有子项的自定义视图类中的布局“继承”?

我有一个名为card.xml 的布局,它是名为Card.kt 的自定义类的“基本”布局。我有一个样式(@style/homepage_block),它适用于基本情况。 卡.xml 我有一个名为 card.xml 的布局,它是名为 Card.kt 的自定义类的“基本”布局。我有一个适合它的风格(@style/homepage_block),它适用于基本情况。 card.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="vertical" android:divider="@drawable/separator_horizontal_empty_10" android:showDividers="middle" style="@style/homepage_block"> <!-- i set orientation and divider --> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/block_title" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/homepage_block_title"> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="match_parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:text="TITLE" style="@style/text.Header" /> </androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout> 卡.kt package com.tempapplication.views import android.content.Context import android.util.AttributeSet import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.LinearLayout import com.tempapplication.R import com.tempapplication.databinding.CardBinding class Card @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 ) : LinearLayout(context, attrs, defStyleAttr, defStyleRes) { private val binding: CardBinding init { LayoutInflater.from(context).inflate(R.layout.card, this, true) binding = CardBinding.bind(this) initAttributes(attrs, defStyleAttr, defStyleRes) } // i have a custom attribute called title which i use to set the title text private fun initAttributes(attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) { if (attrs == null) { return } val typedArray = context.obtainStyledAttributes(attrs, R.styleable.Card, defStyleAttr, defStyleRes) binding.title.text = typedArray.getString(R.styleable.Card_title) typedArray.recycle() } override fun addView(child: View?, params: ViewGroup.LayoutParams?) { super.addView(child, params) } } attrs.xml <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="Card"> <attr name="title" format="string" /> </declare-styleable> </resources> 所以进一步的问题可以分成两部分。 第一个问题 我可以以某种方式将属性从card.xml“继承”到我使用此布局的自定义视图吗?例如,在 card.xml 中,我将线性布局方向设置为 vertical 并且还有一个自定义分隔线。但是当我在某些活动中包含自定义视图时,它似乎根本不知道它(是它应该是什么样子,以及它实际上是什么样子),所以我必须手动设置分隔符和包含此自定义视图时的方向。 activity.xml <com.tempapplication.views.Card android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:divider="@drawable/separator_horizontal_empty_10" android:showDividers="middle" app:title="PAGE OF WEEK" > <!-- i set orientation and divider even when they are set in card.xml --> <include layout="@layout/content_week" bind:data="@{data.week}"/> </com.tempapplication.views.Card> 也许我需要将分隔线和方向放入style资源中?还是有更优雅的方法来做到这一点? 第二个问题 我有子视图(如上面的代码中包含布局content_week)。如何使根线性布局 (card.xml) 的初始 @style/homepage_block 样式影响我包含在卡片视图中的子项?例如,我希望 Card 的所有子项都有红色背景,因为 card.xml 中使用了样式资源。有可能吗? content_week.xml <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <data> <variable name="data" type="com.tempapplication.modules.HomepageBlockWeekData"/> </data> <LinearLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:divider="@drawable/separator_horizontal_empty_10" android:showDividers="middle" style="@style/homepage_block_content"> <TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:gravity="center_vertical" android:text="@{data.title}" style="@style/text.Header" /> <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/_1pxh" android:backgroundTint="#FFCAC4D0" android:background="@drawable/separator" /> <TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:text="@{data.description}" style="@style/text" /> </LinearLayout> </layout> 您的问题围绕在 Android 中创建自定义视图以及从包含的布局继承样式和属性进行。我将分别解决每个问题: 第一个问题:继承属性 在自定义 Card 视图中,您将根据 card.xml 中定义的自定义属性来扩充 attrs.xml 布局并设置属性。但是,直接在 XML 中为 android:orientation 视图的父布局设置的 android:divider、android:showDividers 和 Card 等属性不会自动应用于自定义视图。 如果您想从父 XML 继承这些属性,您可以通过修改您的 Card 类来实现: class Card @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 ) : LinearLayout(context, attrs, defStyleAttr, defStyleRes) { // ... (other code remains the same) init { LayoutInflater.from(context).inflate(R.layout.card, this, true) binding = CardBinding.bind(this) // Apply attributes from XML to the custom view val attributes = context.obtainStyledAttributes(attrs, R.styleable.Card, defStyleAttr, defStyleRes) applyAttributes(attributes) attributes.recycle() initAttributes(attrs, defStyleAttr, defStyleRes) } private fun applyAttributes(attrs: TypedArray) { val orientation = attrs.getInt(R.styleable.Card_android_orientation, VERTICAL) val divider = attrs.getDrawable(R.styleable.Card_android_divider) val showDividers = attrs.getInt(R.styleable.Card_android_showDividers, SHOW_DIVIDER_NONE) orientation = VERTICAL // Force vertical orientation for the LinearLayout divider?.let { setDividerDrawable(divider) } setShowDividers(showDividers) } // ... (other code remains the same) } 在此代码中,我添加了一个 applyAttributes 函数,该函数从自定义属性获取的 android:orientation 中读取 android:divider、android:showDividers 和 TypedArray 等属性的值。然后,该函数将这些属性应用到自定义视图,确保继承父 XML 布局中设置的属性。 第二个问题:将样式应用于子视图 如果您希望 Card 自定义视图中的子视图继承 card.xml 布局中定义的样式,则需要为子视图设置适当的样式。在 content_week.xml 中,您可以通过在 style 属性中引用样式来应用样式: <TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:gravity="center_vertical" android:text="@{data.title}" style="@style/text.Header" /> <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/_1pxh" android:backgroundTint="#FFCAC4D0" android:background="@drawable/separator" style="@style/homepage_block_content_separator" /> <TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:text="@{data.description}" style="@style/text" /> 在这里,我向子视图添加了 style 属性以应用相关样式。确保在样式资源中定义这些样式(@style/text.Header、@style/homepage_block_content_separator等),并且它们应该应用于子视图。 请记住,设置样式时,您需要确保样式在样式资源中正确定义 (styles.xml),并且它们与您要应用它们的特定视图类型的属性和特性兼容。

回答 1 投票 0

是否可以将多种风格合而为一?

我有两种风格,称之为A和B。是否可以: 将它们应用到同一个 UI 元素,或者 将它们组合成一个单一的风格(基本上只是为了让我 完成...

回答 2 投票 0

在 Material3 中更改 ActionMode 背景颜色

从 Material3 开始,我无法更改动作模式背景颜色。 在 Material3 之前,我设法使用 actionModeBackground 属性更改背景颜色: 从 Material3 开始,我无法更改动作模式背景颜色。 在Material3之前,我设法用actionModeBackground属性改变了背景颜色: <item name="actionModeBackground">@color/some_color</item> 这是我的主题: <style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar"> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="windowActionModeOverlay">false</item> <item name="actionModeBackground">@color/action_mode_background</item> <item name="android:actionModeCloseDrawable">@drawable/ic_baseline_done_tick_24</item> </style> 我也检查了this线程但似乎不适用于material3. 如何在 Material3 上更改它? 谢谢!

回答 0 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.