标签: android-styles

更改CalendarView样式

我正在尝试在我的应用程序中添加CalendarView,它使用Theme.Light主题.问题是,此日历的天数以白色呈现,因此在使用灯光主题时,您无法看到它们.

现在,我在XML布局文件中有以下代码:

<CalendarView
    android:id="@+id/calendar1"
    android:layout_width="500dp"
    android:layout_height="300dp"/>
Run Code Online (Sandbox Code Playgroud)

我试图像这样强制日历主题:

<CalendarView
    android:id="@+id/calendar1"
    android:layout_width="500dp"
    android:layout_height="300dp"
    android:theme="@android:style/Theme.Light" />
Run Code Online (Sandbox Code Playgroud)

但它没有改变任何东西.我想我应该用android:dateTextAppearance属性做一些事情,所以我尝试了这个:

<CalendarView
    android:id="@+id/calendar1"
    android:layout_width="500dp"
    android:layout_height="300dp"
    android:dateTextAppearance="@android:style/TextAppearance.Large.Inverse" />
Run Code Online (Sandbox Code Playgroud)

但它也没有做任何事情.

有任何想法吗 ?

谢谢 !

android android-widget android-calendar android-styles

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

如何在android中提供大胆的风格?

如何在styles.xml中提供粗体和普通样式?我给出的代码是:

<style name="textbold" parent="@android:style/TextAppearance">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textstyle">bold</item>
</style>
<style name="textregular" parent="@android:style/TextAppearance">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textstyle">normal</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但它在这里显示错误: <item name="android:textstyle">

android android-styles

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

Android样式:'style ="@ android:style/XYZ"'和'style ="?android:attr/XYZ"'之间的区别?

我试图将按钮样式设置为我在Android Full Width ICS样式Minimalist Bottom ButtonsViews中询问的那些.

我成功了,对于任何感兴趣的人都有以下xml:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:divider="@android:drawable/divider_horizontal_dark"
        android:gravity="bottom"
        android:orientation="vertical"
        android:paddingTop="16dip"
        android:showDividers="beginning|end" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:measureWithLargestChild="true"
            android:orientation="horizontal"
            android:divider="@android:drawable/divider_horizontal_dark"
            android:showDividers="middle" >                             


            <Button
                android:id="@+id/cancel_button"
                style="?android:attr/buttonBarButtonStyle"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_weight="1"
                android:maxLines="2"
                android:text="@string/cancel_button" />

            <Button
                android:id="@+id/login_button"
                style="?android:attr/buttonBarButtonStyle"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_weight="1"
                android:filterTouchesWhenObscured="true"
                android:maxLines="2"
                android:text="@string/login_button" />

        </LinearLayout>
    </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

但有一个问题.eclipse内容辅助不知道以下资源解析发生了什么:

style="?android:attr/buttonBarButtonStyle"

我熟悉典型的分辨率(eclipse的内容辅助知道)

style=@android/style/...

......但我不清楚两者之间的区别.似乎某些样式属性出现在一个而不是另一个.例如,以下内容无法解决任何问题:

style=@android:attr/buttonBarStyle

这两个都没有:

style="@android:style/buttonBarStyle

所以我想这里有两个问题:

  1. 为什么资源引用语法有所不同?
  2. 为什么在attr类别下混淆样式的错误分类.
  3. 什么是attr类别甚至再次使用?

谢谢!

android android-layout android-resources android-styles

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

对话框中的自定义复选框样

我正在构建一个包含多项选项(复选框)的对话框:

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setMultiChoiceItems(arrayResource, selectedItems, new DialogInterface.OnMultiChoiceClickListener() {
    // ...
});

AlertDialog dialog = builder.create();
dialog.show();
Run Code Online (Sandbox Code Playgroud)

我有一个复选框的自定义样式:

<style name="CustomCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
    <item name="android:button">@drawable/btn_check</item>
    <item name="android:textColor">@android:color/holo_purple</item>
</style>
Run Code Online (Sandbox Code Playgroud)

通过设置应用于布局中的各个复选框时,它可以很好地工作style="@style/CustomCheckBox".

但是,如何将此样式应用于创建的对话框?或者对整个主题来说......

如果它有点相关 - 我正在使用minSdkVersion=14targetSdkVersion=19.


更新:

现在根据MattMatt的回答,我将自定义复选框样式应用于整个主题,并为对话框设置自定义样式:

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:checkboxStyle">@style/CustomCheckBox</item>
    <item name="android:dialogTheme">@style/CustomDialog</item>
    <item name="android:alertDialogTheme">@style/CustomDialog</item>
</style>

<style name="CustomCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
    <item name="android:button">@drawable/btn_check</item>
    <item name="android:checkMark">@drawable/btn_check</item>
</style>

<style name="CustomDialog" parent="@android:style/Theme.Holo.Light.Dialog">
    <item name="android:checkboxStyle">@style/CustomCheckBox</item>
    <item name="android:background">#aaf</item>
</style>
Run Code Online (Sandbox Code Playgroud)

现在添加到布局的任何复选框都会获得自定义样式,我可以更改对话框的背景,但对话框中的复选框不会受到任何影响......

checkbox android android-theme android-dialog android-styles

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

在Android中更改Switch的颜色

我正在尝试更改Android中交换机的颜色.我意识到我需要新的9件.我去了http://android-holo-colors.com/并选择了我的颜色并选择了(Switch Jelly Bean).要使用Switch Jelly Bean,我必须使用:https://github.com/BoD/android-switch-backport.要将它导入我的项目,我必须添加:

<item name="switchStyle">@style/Widget.Holo.CompoundButton.Switch</item>

到我的样式,然后在xml我必须像这样使用开关:

<org.jraf.android.backport.switchwidget.Switch android:layout_width="wrap_content" android:layout_height="wrap_content" />

现在用开关的一切工作正常.接下来,我从android全息颜色生成器输出所有内容并将其放入正确的文件中:

  • drawable(2个选择器文件)
  • drawable-hdpi(9个补丁文件)
  • drawable-xhdpi(9个补丁文件)
  • drawable-xxhdpi(9个补丁文件)

然后我添加到我的xml:

<org.jraf.android.backport.switchwidget.Switch android:layout_width="wrap_content" android:layout_height="wrap_content" android:thumb="@drawable/apptheme_switch_inner_holo_light" android:track="@drawable/apptheme_switch_track_holo_light" />

但它仍然是原始的蓝色.我相信我正在做的一切正确.一切都编译(xml,java).注意:我org.jraf.android.backport.switchwidget.Switch也在我的java中导入.有任何想法吗?

java xml android android-theme android-styles

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

如何从我的应用主题中获取原色?

在我的Android java代码中,如何在我的主题中引用颜色"colorPrimary"?

我有以下主题定义:

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">

    <item name="colorPrimary">@color/myColor1</item>
    <item name="colorPrimaryDark">@color/myColor2</item>      
    <item name="colorControlNormal">@color/myColor3</item>
    <item name="colorControlActivated">@color/myColor4</item>

</style>
Run Code Online (Sandbox Code Playgroud)

我可以直接引用颜色资源(R.color.myColor1),但我更喜欢引用主题的primaryColor设置,以便在将来colorPrimary更改时保持一致.

这可能吗?

android android-xml android-theme android-styles android-color

13
推荐指数
2
解决办法
8850
查看次数

AlertDialog 中的样式单选按钮和文本

我想在带有自定义样式的 AlertDialog 中显示一个单选列表,例如 这个.

所以我创建了一个自定义主题并将其作为参数提供给 AlertDialog.Builder 的构造函数。

这是显示对话框的代码:

private void showSortDialog() {
final CharSequence[] options = new String[] {"Relevance", "Newest"};
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivityReference(),
                                                          R.style.RadioDialogTheme);
    builder.setTitle("Sort by");
    builder.setSingleChoiceItems(options, -1, new DialogInterface.OnClickListener() {
    . . . . 
    builder.create().show();
}
Run Code Online (Sandbox Code Playgroud)

这是样式:

<style name="RadioDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:textColorAlertDialogListItem">@drawable/radiobutton_textcolor_selector
    </item>
    <item name="android:listChoiceIndicatorSingle">@drawable/apptheme_btn_radio_holo_light
    </item>
</style>
Run Code Online (Sandbox Code Playgroud)

我能够找到我在样式中添加的几个属性,以根据它们的状态更改单选按钮/文本的颜色。但我无法自定义文本外观(我想更改大小、提供填充等)。

我确定有一些属性可以用来设置文本的样式,但我找不到它。任何人都可以帮我解决这个问题吗?谢谢。

android android-theme android-alertdialog android-styles

13
推荐指数
1
解决办法
6122
查看次数

禁用Tablayout上的材质波纹

我正在尝试删除TabLayout选项卡上的材质波纹效果.

我想知道是否可以这样做?

有什么想法吗?

我已经尝试将stateListAnimator设置为null但它仍然无效

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stateListAnimator="@null"/>
Run Code Online (Sandbox Code Playgroud)

android android-styles

13
推荐指数
4
解决办法
6376
查看次数

如何更改SearchView元素的颜色?

我想在我的项目中使用SearchView,但我的元素颜色有问题.让我告诉你:它的fragmentDialog我有我的SearchView 你可以在这看到我的意思

我不需要改变bg颜色.下一张图片就是例如.我想看看没有黑色bg的SearchView元素. 元素的颜色是白色

我试过了

  • 改变主题
  • 改变风格
  • 改变色彩

但没有任何工作.搜索图标和anoter元素仍然是白色的.也许我失去了什么?我可以用XML做到这一点吗?请帮我.

android android-theme android-search android-styles

13
推荐指数
6
解决办法
3万
查看次数

如何从 MaterialComponents.DayNight 主题更改工具栏文本颜色?

我在我的应用程序中使用 MaterialComponents.DayNight 主题。在白天模式下,工具栏文本颜色为黑色。但是当我切换到夜间模式工具栏文本颜色保持黑色,所以它不再可见。

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
Run Code Online (Sandbox Code Playgroud)

我想在夜间模式下将工具栏文本颜色更改为白色。我怎样才能做到这一点?

android android-styles android-toolbar material-components material-components-android

13
推荐指数
4
解决办法
4653
查看次数