标签: android-styles

在Android XML中,我可以将buttonStyleSmall或Button.Small设置为自定义样式的父样式吗?

我想扩展Android的小按钮风格.我可以内联:

<Button android:id="@+id/myButton"
        style="?android:attr/buttonStyleSmall"
        android:layout_alignParentRight="true"
        android:layout_gravity="right"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:textSize="10dp"
        android:text="Click Here"/>
Run Code Online (Sandbox Code Playgroud)

但为了可重用性,我想将这些样式转换为自定义样式.如何将buttonStyleSmall(或Widget.Button.Small?)作为父项添加到样式中?在我的自定义样式XML中这样的东西:

<style name="RightLink" parent="?android:attr/buttonStyleSmall">
  <item name="android:layout_alignParentRight">true</item>
  <item name="android:layout_gravity">right</item>
  <item name="android:layout_height">wrap_content</item>
  <item name="android:layout_width">wrap_content</item>
  <item name="android:paddingLeft">2dp</item>
  <item name="android:paddingRight">2dp</item>
  <item name="android:textSize">10dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)

使用该样式的按钮声明:

<Button android:id="@+id/myButton"
        style="@style/RightLink"
        android:text="Click Here"/>
Run Code Online (Sandbox Code Playgroud)

编辑

使用下面Lukas描述的正确语法(@android:attr/buttonStyleSmall用作父母),我仍然看到两者之间的区别:

使用buttonStyleSmall作为样式和内联样式的按钮:

PIC1

使用buttonStyleSmall作为父级的自定义样式:

PIC2

我错过了什么?

android android-layout android-xml android-styles

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

自定义Android ScrollView的垂直滚动条

我需要自定义ScrollView所以它看起来像在图片中: 在此输入图像描述
我已经成功定制了ThumbTrack,但我不知道如何Arrows在我提供的图片中添加.

这是我正在使用的风格:

<!-- Scrollbar -->
    <style name="scroll_view">  
        <item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
        <item name="android:scrollbars">vertical</item>
        <item name="android:fadeScrollbars">false</item>
        <item name="android:scrollbarThumbVertical">@drawable/sb_thumb</item>
        <item name="android:scrollbarTrackVertical">@drawable/sb_track_vertical_bg</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

Arrows应该是一部分ScrollView的风格,以避免额外的空格和也,他们需要简单,无点击,并等

android android-layout android-scrollview android-view android-styles

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

如何制作透明的AppCompat风格?

我的活动风格必须来自AppCompat主题.

所以我在清单中制作自定义样式并设置活动样式.

但是显示了黑色背景.

以下是自定义主题

<style name="TransparentTheme" parent="@style/Theme.AppCompat">

    <item name="android:background">@null</item>
    <item name="background">@null</item>

    <item name="android:windowBackground">@null</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowAnimationStyle">@null</item>
</style>
Run Code Online (Sandbox Code Playgroud)

android android-appcompat android-theme android-styles

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

无法删除活动中的标题栏

我想在我的活动之上删除标题.我尝试了这两种方式,但不是在api级别8.

1:

<style name="NOtitleTheme" parent="Theme.AppCompat.Light">
<item name="android:windowFullscreen">true</item>
   <item name="android:windowNoTitle">true</item> </style>
Run Code Online (Sandbox Code Playgroud)

2:

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Run Code Online (Sandbox Code Playgroud)

知道为什么这不起作用api 8

一旦我设法删除它api 8,但我不记得如何.


编辑:

解决了!问题是 this.requestWindowFeature(Window.FEATURE_NO_TITLE)在API 8 <item name="android:windowNoTitle">true</item>上不起作用,也不起作用,但是 actionBar.hide()工作,getSupportActionBar()返回null的原因是之前使用了两个选项之一,我只是忘了删除它们.当我删除一个我添加其他(多么愚蠢!)谢谢所有!(抱歉英文不好)

android android-activity android-styles android-actionbaractivity

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

getSupportActionBar().setCustomView(view)不会填充整个操作栏

我正在尝试设置我的应用程序的自定义视图,我制作的布局没有填满整个操作栏.我尝试了很多样式设置,但没有一个适合我.

这是我的活动代码

View view = getLayoutInflater().inflate(R.layout.actionbar_customized_home, null);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(view);
Run Code Online (Sandbox Code Playgroud)

这里的布局设置为视图

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/actionbar_color"
    >
![enter image description here][1]

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="25dp"
        android:layout_centerInParent="true"
        android:scaleType="fitCenter"
        android:src="@drawable/logo"/>



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

甚至像导航器这样的菜单项的背景如何将我的自定义视图作为背景颜色?

我非常感谢你的帮助

android android-styles android-actionbar-compat android-actionbaractivity

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

检索项目的父项时出错:找不到与给定名称"android:Theme.Material.Light"匹配的资源

我在styles.xml中收到此错误:

检索项目的父项时出错:找不到与给定名称"android:Theme.Material.Light"匹配的资源.

在清单中:

<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="21" />
Run Code Online (Sandbox Code Playgroud)

Android Sdk经理:

我更新了所有的api 21和额外内容.

在此输入图像描述

在此输入图像描述

在订单和出口:

在此输入图像描述

值-V21/styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="android:Theme.Material.Light">

        <item name="android:colorPrimary">@color/primary</item>
        <item name="android:colorPrimaryDark">@color/primary_dark</item>
        <item name="android:colorAccent">@color/accent</item>
        <item name="android:textColorPrimary">@color/text_primary</item>
        <item name="android:textColor">@color/text_secondary</item>
        <item name="android:navigationBarColor">@color/primary_dark</item>

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

安慰:

E:\workspace\WelcomeToL\app\src\main\res\values-v21\styles.xml:3: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light'.

E:\workspace\WelcomeToL\app\src\main\res\values-v21\styles.xml:7: error: Error: No resource found that matches the given name: attr 'android:colorAccent'.

E:\workspace\WelcomeToL\app\src\main\res\values-v21\styles.xml:5: error: Error: No resource found that matches the given name: attr 'android:colorPrimary'.

E:\workspace\WelcomeToL\app\src\main\res\values-v21\styles.xml:6: error: …
Run Code Online (Sandbox Code Playgroud)

android android-styles android-5.0-lollipop

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

Android - 覆盖每个主题的样式

有没有办法根据活动上设置的主题来更改样式?例如,假设我的活动有一个样式设置为TextViewStyle的textview

<TextView
   style="@style/TextViewStyle"        
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="Text"/>
Run Code Online (Sandbox Code Playgroud)

这是我的TextViewStyle

<style name="TextViewStyle" parent="android:style/Widget.TextView">
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">8sp</item>
        <item name="android:textColor">@android:color/holo_blue_dark</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

在我的Styles.xml中,我有两个主题

 <style name="AppThemeLight" parent="android:Theme.Material.Light">

   </style>


   <style name="AppThemeDark" parent="android:Theme.Material">

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

现在,当我将主题设置为Dark时,我希望此主题覆盖我在TextViewStyle中设置的某些值.我怎么能这样做?我尝试了以下,但它不起作用

    <!-- Override TextViewStyle style for AppThemeLight-->
            <style name ="AppThemeLight.TextBlockStyle" parent="@style/TextBlockStyle">
                <item name="android:textColor">@color/my_purple</item>
                <item name="android:textSize">20sp</item>
            </style>
<!-- Override TextViewStyle style for AppThemeDark-->
            <style name ="AppThemeDark.TextBlockStyle" parent="@style/TextBlockStyle">
                <item name="android:textColor">@color/my_green</item>
                <item name="android:textSize">40sp</item>
            </style>
Run Code Online (Sandbox Code Playgroud)

android styles android-theme android-styles

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

是否可以从自定义属性继承或扩展样式

我正在创建一个库,需要通过主题将父样式传递到库中.要实现这一点,x是库中定义的样式.但它需要从父母那里扩展一些东西.

可以这样做吗?

我的图书馆风格: -

<style="x" parent="?customAttrReferingToSomeOtherStyle"></style>
Run Code Online (Sandbox Code Playgroud)

使用我的图书馆的任何人都需要这样做: -

<item name="customAttrReferingToSomeOtherStyle">@style/ApprelatedStyle</item>
Run Code Online (Sandbox Code Playgroud)

我对编写父样式的硬编码不感兴趣.我希望它是基于自定义属性的纯粹引用.任何形式的硬编码风格都会在模块设置中击败关注点.

android android-theme android-styles

9
推荐指数
0
解决办法
150
查看次数

Android“?colorPrimary”与“?attr/colorPrimary”?

我找不到任何关于以下差异的信息:

android:textColor="?attr/colorPrimary"
Run Code Online (Sandbox Code Playgroud)

对比

android:textColor="?colorPrimary"
Run Code Online (Sandbox Code Playgroud)

我读过“?attr”表示当前主题中指定的属性值,但没有“attr”它会给出相同的结果(=我的主题中定义的颜色)。它的行为与其他属性相似吗?

例如:

是否android:background="?attr/selectableItemBackground" 等于android:background="?selectableItemBackground"

据说这里有所不同。

非常感谢。

android android-styles android-attributes

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

android:background 在 style.xml 中不起作用

任何人都可以就以下问题提出建议。

我尝试使用具有 drawable(curve_button.xml) 文件的自定义按钮样式。

颜色已经应用并且看起来不错,但它似乎有问题, <item name="android:background">@drawable/curve_button</item>因为它没有应用。

样式文件

 <style name="CustomButton" parent="Widget.AppCompat.Button.Borderless.Colored">
    <item name="colorButtonNormal">@color/book_appointment</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:background">@drawable/curve_button</item>
  </style> 
Run Code Online (Sandbox Code Playgroud)

曲线按钮.xml

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
  <item>
    <shape android:shape="rectangle">
      <padding
         android:paddingLeft="34dp"
         android:paddingRight="34.4dp"
         android:paddingTop="16dp"
         android:paddingBottom="16dp"
        />
      <corners android:radius="8dip" />          
    </shape>
  </item>
</selector>
Run Code Online (Sandbox Code Playgroud)

按钮布局

<Button
            android:id="@+id/idBookAppontment"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="Book Appointment"
            android:theme="@style/CustomButton"
            android:layout_marginBottom="12dp"
            android:layout_marginTop="6dp"
            android:layout_marginLeft="38dp"
            android:layout_marginRight="37dp"            
            android:inputType="textCapWords"
            android:layout_gravity="bottom"
            local:MvxBind="Typeface StringToFont('Effra_Rg')"
            android:layout_below="@id/providerTabbarHost"
            android:layout_alignParentBottom="true" />
Run Code Online (Sandbox Code Playgroud)

android android-layout android-styles

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