在我的应用程序中,我想将8 dip的上下边距设置为textview.所以,如果我这样做 -
<TextView
android:id="@+id/tv_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/settings_plain_text"/>
Run Code Online (Sandbox Code Playgroud)
它的风格内容很好 -
<style name="settings_plain_text">
<item name="android:layout_marginTop"> 8dip </item>
<item name="android:layout_marginBottom"> 8dip </item>
<item name="android:textSize"> 18sp </item>
</style>
Run Code Online (Sandbox Code Playgroud)
但是当我以编程方式将相同的样式应用于textview时 -
textview.setTextAppearance(context, R.style.settings_plain_text);
Run Code Online (Sandbox Code Playgroud)
它没有显示我设置的顶部和底部边距.请帮忙.
我正在尝试构建使用appcompat_v7库的Android项目.
为此,我通过Eclipse创建了我的项目 - > New Android Sample Project并添加了我的自定义styles.xml,然后添加了appcompat_v7库Project - > Properties - > Android - > Add.
但是当我编译项目时,我在appcompat_v7/res/values/styles_base.xml中收到以下错误:
appcompat_v7/res/values/styles_base.xml:24: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Base'.
appcompat_v7/res/values/styles_base.xml:84: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Base'.
appcompat_v7/res/values/styles_base.xml:166: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Base'.
appcompat_v7/res/values/styles_base.xml:243: error: Error retrieving parent for item: No resource found that matches the given …Run Code Online (Sandbox Code Playgroud) android coding-style android-appcompat android-theme android-styles
我正在使用RecyclerView圆角,使其圆角我在XML下面使用:
view_rounded.xml: -
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#008f8471"/>
<stroke android:width="2dp" android:color="#ffffff" />
<corners android:radius="10dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
fragment_main.xml: -
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/view_rounded"/>
Run Code Online (Sandbox Code Playgroud)
adapter_main.xml: -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textTitle"
style="@style/AppTheme.ListTextView"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
style.xml: -
<style name="AppTheme.ListTextView" parent="android:Widget.Material.TextView">
<item name="android:gravity">left</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textAllCaps">false</item>
<item name="android:padding">10dp</item>
<item name="android:textAppearance">@android:style/TextAppearance.DeviceDefault.Medium</item>
<item name="android:textColor">@color/tabsScrollColor</item>
<item name="android:textStyle">bold</item>
</style>
Run Code Online (Sandbox Code Playgroud)
获取(没有项目分隔符):

必需(带项目分隔符):

我正在创建一个普通的Checkbox视图:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)

浅绿色(#A5D6A7)是由主要风格定义的强调色:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorAccent">@color/green_light</item>
Run Code Online (Sandbox Code Playgroud)
我已经发现我无法在运行时更改此样式:如何在代码中设置colorAccent?
我想要的是在特定的复选框上更改此颜色,而不是全局覆盖应用程序.我可以在不创建特定资产的情况下完成吗?因为用户可以在运行时更改此颜色.
谢谢!
我正在尝试在我的应用程序中添加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)
但它也没有做任何事情.
有任何想法吗 ?
谢谢 !
在我的应用中,我有一个显示搜索建议的搜索视图.我希望下拉/微调器和文本是一种特定的颜色.目前我唯一能做的改变是输入文本的文字颜色如下:
<style name="MyApp.AutoCompleteTextView" parent="Widget.AppCompat.Light.AutoCompleteTextView">
<item name="android:textColor">@color/white</item>
<item name="android:textCursorDrawable">@null</item>
<item name="android:background">@color/myBackgroundColor</item>
</style>
Run Code Online (Sandbox Code Playgroud)
该应用当前显示的搜索结果结果如下:

我想知道的是如何更改searchHint颜色,下拉背景和下拉项目文本颜色等部分?
我的目标是API 19+
android android-actionbar searchview android-styles android-toolbar
我在我的项目中使用android.support.v7.widget.Toolbar.默认情况下,在灯光主题中它有黑色动作溢出菜单图标,黑色标题和黑色溢出菜单文本颜色,就像那样(不要看导航图标 - 它是自定义的):

但在我的应用程序中,我需要它是白色的.我在工具栏的样式中将android:textColorPrimary设置为白色:
<style name="Widget.My.Toolbar" parent="Widget.AppCompat.Toolbar">
<item name="theme">@style/ThemeOverlay.My.Toolbar</item>
</style>
<style name="ThemeOverlay.My.Toolbar" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
它改变了标题的颜色和溢出菜单按钮,就像我想要的那样,但它也改变了Action owerflow菜单项的文字颜色:

它看起来很难看.我甚至试过以编程方式设置标题颜色
toolbar.setTitleTextColor(getResources.getColor(R.color.white);
Run Code Online (Sandbox Code Playgroud)
但它只改变标题颜色,而不是更改菜单按钮:

那么除了动作溢出菜单中的项目外,如何更改工具栏中所有内容的颜色?
我正在使用书法库在我的应用程序中使用自定义字体.我使用默认字体在我的整个应用程序中设置了一个自定义字体CalligraphyConfig,在我Application的#onCreate()方法中,它工作正常.当我需要更改一个活动的字体(SettingsActivity)时出现问题.
我尝试在样式中使用自定义字体,但它没有更改活动的字体.
以下是Style的代码
<style name="EnglishActivitiesTheme" parent="AppTheme">
<item name="android:textViewStyle">@style/AppTheme.Widget.TextView</item>
</style>
<style name="AppTheme.Widget.TextView" parent="android:Widget.Holo.Light.TextView">
<item name="fontPath">fonts/Roboto-Regular.ttf</item>
</style>
Run Code Online (Sandbox Code Playgroud)
在清单中
<activity
android:name=".SettingsActivity"
android:theme="@style/EnglishActivitiesTheme"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
Run Code Online (Sandbox Code Playgroud)
我是否通过样式方法使用自定义字体做错了什么?或者有更好的方法吗?
我的工具栏文本,后退箭头和所有颜色都是黑色但我希望它是白色
我怎样才能实现它?
我的styles.xml看起来像这样:
<resources>
<style name="AppTheme" parent="MyMaterialTheme.Base">
</style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/windowBackground</item>
<item name="android:textColor">@color/textColorPrimary</item>
<item name="android:textStyle">normal</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
Android Manifest代码段:
<application
android:allowBackup="true"
android:icon="@mipmap/hello"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
Run Code Online (Sandbox Code Playgroud) 我正在尝试更改活动操作栏的背景颜色和标题颜色,我尝试了官方教程和一些答案,但没有一个对我有用,我错过了一些东西.
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Run Code Online (Sandbox Code Playgroud)
styles.xml(v21)
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
主要活动 :
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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" android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton android:id="@+id/fab" …Run Code Online (Sandbox Code Playgroud) android ×10
android-styles ×10
android-xml ×1
checkbox ×1
coding-style ×1
colors ×1
fonts ×1
searchview ×1
xml ×1