相关疑难解决方法(0)

Android主题 - 如何仅为特定视图类型设置样式

是否可以创建一个仅为特定视图类型设置样式的主题?例如,如果我希望FrameLayout对象的背景为一种颜色,但是将所有其他视图保留为主题的默认背景颜色,我该怎么做?

CSS并行将是div {background-color:#000000;}.我怎么能在android中做到这一点?

编辑:我发现TextView只有:android:textViewStyle,你可以只为TextViews 选择一种风格.但其他观点呢?甚至自定义视图?FrameLayout具体看?

android android-styles

10
推荐指数
0
解决办法
1333
查看次数

覆盖引用的样式属性

阅读参考主题属性后,我试图在我设置的自定义主题中引用属性的值.

我将用户定义的样式应用于 CheckedTextView

<CheckedTextView
    android:id="@+id/contactInfo"
    style="@style/ListViewCheckedTextViewRowStyle" >
</CheckedTextView>
Run Code Online (Sandbox Code Playgroud)

用户定义的样式定义为:

<style name="ListViewCheckedTextViewRowStyle" parent="@style/ListViewRowStyle">
    <item name="android:checkMark">?android:listChoiceIndicatorMultiple</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我创建的主题定义为:

<style name="Theme.Yellowgreen" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:listChoiceIndicatorMultiple">@drawable/btn_check_holo_light</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但是,显示的checkMark样式是设备的默认主题的drawable,而不是我的用户定义的drawable.

我可以显示可绘制的唯一方法是:

<style name="ListViewCheckedTextViewRowStyle" parent="@style/ListViewRowStyle">
    <item name="android:checkMark">@drawable/btn_check_holo_light</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但这违背了覆盖此属性的整个目的,特别是因为我想在多个主题中覆盖此属性.

我在onCreate()我的方法中设置主题Activity:

public void onCreate(Bundle savedInstanceState) {
    this.setTheme(R.style.Theme_Yellowgreen);
    super.onCreate(savedInstanceState);
    // ...
}
Run Code Online (Sandbox Code Playgroud)

我还尝试在AndroidManifest.xml文件中设置主题,如:

<application android:theme="@style/Theme.Yellowgreen" >
Run Code Online (Sandbox Code Playgroud)

但那没用.怎么可能出错?

更新

我刚刚创建了一个小型示例项目,看起来我上面发布的代码正在运行.所以我必须有一些其他样式覆盖这个属性,或者它可能与我的布局xml文件有关.

在我的大项目中,我有两个FragmentsActivity.两者Fragments都有Listviews支持Adapters.在Fragment A所述getView()的方法Adapter如下:

public View getView(final int position, View convertView, …
Run Code Online (Sandbox Code Playgroud)

android themes styles overriding checkedtextview

9
推荐指数
1
解决办法
3万
查看次数

如何在Android中更改标签样式?

我希望我的Android标签看起来像官方TWitter应用程序中那样扁平和简单.如何使用样式/主题定义覆盖默认(浅色)主题并更改选项卡的背景图像?

tabs android themes coding-style

8
推荐指数
1
解决办法
3万
查看次数

如何将样式应用到我拥有的所有TextViews?

可能重复:为
所有TextView(或自定义视图)设置样式,而不将style属性添加到每个TextView

TextView我的应用程序中有很多s.它们有各种各样的字体大小,颜色等等.我需要应用它们android:shadowColorandroid:shadowRadius让它们全部带有阴影.怎么做?

例如,我可以为TextView具有必要属性的s 制作样式

<style name="text_views">
    <item name="android:shadowColor">@color/tv_shadow</item>
    <item name="android:shadowDy">1</item>
    <item name="android:shadowRadius">0.7</item>
</style>
Run Code Online (Sandbox Code Playgroud)

并将其应用于每个TextView.是否可以将阴影的属性包含在应用程序的主题中?

android themes textview

5
推荐指数
2
解决办法
2万
查看次数

具有AppCompat用法的TextView样式的父样式

如果我想设置全局textViewStyle并保持与AppCompat的向后兼容性,我应该使用哪种父样式?我找不到像Widget.AppCompat.TextView这样的东西:

<style name="Base_AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

    <item name="android:textViewStyle">@style/GlobalTextViewStyle</item>

</style>

<style name="GlobalTextViewStyle" parent="?????">
    <item name="android:textAppearance">@style/TextAppearance.AppCompat.Medium</item>
</style>
Run Code Online (Sandbox Code Playgroud)

android textview android-appcompat android-support-library android-styles

4
推荐指数
2
解决办法
3885
查看次数

仅将样式应用于特定TextView

我有两个主题,我在Android应用程序之间来回切换.在某些地方,我TextView想要保持默认颜色.在其他地方,我希望它们是另一种颜色(让我们说橙色).在改变主题时,我想要TextView以前变成蓝色的s.

有没有办法在Android中执行此操作?我有一些想法,比如html/css中的类标记,但似乎找不到任何东西.

编辑:用html/css等价来澄清我所说的内容:

<div>This text is black</div>
<div class="redDiv">This text is red</div>

.redDiv {
    color:red;
}
Run Code Online (Sandbox Code Playgroud)

xml android

3
推荐指数
1
解决办法
2490
查看次数