在这里他们写道:
要将样式定义应用为主题,必须将样式应用于Android清单中的活动或应用程序.执行此操作时,活动或应用程序中的每个视图都将应用它支持的每个属性.例如,如果将前面示例中的CodeFont样式应用于Activity,则所有支持文本样式属性的View元素都将应用它们.
因此,当我将TextColor设置为Red时,所有带文本的元素都会变为红色吗?CSS样式表中是否有强大的说明符?我只看到styles(style="@style/CodeFont")的概念是切实可行的.
如果除了(或代替)CheckBoxes之外你对RadioButtons感兴趣,请参阅此问题.
尽管存在
<item name="android:layout_gravity">center_horizontal</item>
Run Code Online (Sandbox Code Playgroud)
在样式文件中,两个复选框不居中,但显示为"左对齐".

RES /布局/ activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MyLL"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/cb1"
style="@style/CB_style" />
<CheckBox
android:id="@+id/cb2"
style="@style/CB_style" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
RES /值/ styles.xml
<style name="CB_style" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center</item>
<item name="android:checked">false</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
Run Code Online (Sandbox Code Playgroud)
无论我如何修改样式,红色箭头指向的框的背景颜色都不会从背景中改变.

我该如何改变颜色?我的目标是4.0+而不关心4.0-设备和操作系统.
这是我的styles.xml文件的链接.对不起,由于这个项目属于NDA,我不得不审查一些事情.
我尝试了很多东西,包括:
android:background的windowTitleBackgroundStyleandroid:background的actionBarStyleandroid:background的actionBarWidgetStyleandroid:actionBarItemBackground这些都不起作用.该文本视图似乎始终坚持android:background我的基本主题的值,没有任何东西能够覆盖它.
我错过了什么或做错了什么?
我正在尝试为我的Android应用程序创建自定义搜索栏.我发现了许多解决方案,但所有解决方案都使用"自定义"绘图代码作为背景.我的搜索栏很简单 - 我有一个背景图像(只有一个)和拇指图像.我的问题是缩放:我希望"拇指"和"背景"图像都根据搜索条控件的大小进行缩放.怎么做?有点好笑的是,当使用图像(drawables)作为背景/拇指Android时,默认情况下不会缩放它们但是保留原始大小:)
我想构建一个自定义SeekBar,它有一个辅助进度条,但默认情况下是端到端,显示缓冲数据的进度.
可以把它想象成大多数在线视频播放器(例如youtube)提供的搜索栏.总而言之,我们有默认的搜索栏,默认进度条和辅助进度条,它可以填充颜色,而不管主进度/用户拖动搜索条的缺口,只依赖于缓冲数据.
直到现在我只有正常的搜索栏,它会改变用户拖动/设置进度的颜色.
有人可以帮忙吗?
到目前为止我的代码:
seekbar_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@android:id/background"
android:drawable="@drawable/progress_background_fill"/>
<item android:id="@android:id/progress">
<clip android:drawable="@drawable/progress_fill" />
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
progress_fill.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="180"
android:centerColor="#FFB80000"
android:endColor="#FFFF4400"
android:startColor="#FF470000" />
<corners android:radius="5px" />
<stroke
android:width="2dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
Run Code Online (Sandbox Code Playgroud)
progress_background_fill.xml
<gradient
android:angle="90"
android:centerColor="#FF555555"
android:endColor="#FF555555"
android:startColor="#FF555555" />
<corners android:radius="5px" />
<stroke
android:width="2dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
Run Code Online (Sandbox Code Playgroud)
像这样应用这些xml:
<SeekBar
android:id="@+id/seek_hist_timeline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progressDrawable="@drawable/seekbar_progress" />
Run Code Online (Sandbox Code Playgroud) 我试图让我的所有活动都有一个自定义主题样式,如下所示:

这个主题适用于许多设备,包括Nexus 7,三星Galaxy S4和三星Droid Charge(运行姜饼).但是,在其他设备上,例如HP Slate 7和Motorola Droid RAZR,它最终看起来像这样:

我AndroidManifest.xml的application标签中有以下内容:
android:theme="@style/AppTheme"
Run Code Online (Sandbox Code Playgroud)
主题如下res/values/styles.xml:
<style name="AppBaseTheme" parent="@android:style/Theme.Light.NoTitleBar">
</style>
<style name="AppTheme" parent="@style/AppBaseTheme">
<item name="android:windowBackground">@color/background</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我还加了styles.xml下res/values-v11.这是适用的风格:
<style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light.NoActionBar">
</style>
Run Code Online (Sandbox Code Playgroud)
最后,这似乎在styles.xml下面res/values-v14:
<style name="AppBaseTheme" parent="@android:style/Theme.DeviceDefault.Light">
</style>
Run Code Online (Sandbox Code Playgroud)
我试图为每个活动定义主题并手动使用该setTheme()功能onCreate(),但没有任何效果.我还试图在每个人手动设置一个背景Activity,但这也不起作用.我该怎么做才能解决我的问题?
编辑:有趣的是设置android:background样式使其工作,但是那些不应该有背景的元素也会收到背景颜色.
android android-manifest android-layout android-activity android-styles
红色突出显示表示无法解析符号“主题”

以下是一些配置:
styles.xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<item name="android:windowNoTitle">true</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
。
AndroidManifest.xml
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" />
Run Code Online (Sandbox Code Playgroud)
...
android:theme="@style/AppTheme">
Run Code Online (Sandbox Code Playgroud)
。
build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.0.0'
}
Run Code Online (Sandbox Code Playgroud)
...
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
applicationId 'com.mobile.slider'
minSdkVersion 8
targetSdkVersion 19
Run Code Online (Sandbox Code Playgroud)
。
MainActivity.java
public class …Run Code Online (Sandbox Code Playgroud) 这是我的xml:
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是托管片段.
public class TabPractice extends Fragment{
private FragmentTabHost mTabHost;
//Mandatory Constructor
public TabPractice() {
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tabs_practice,container, false);
mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost);
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("Practice All").setIndicator("Practice All"),
WelcomeScreen.class, null);
mTabHost.addTab(mTabHost.newTabSpec("Practive Fav").setIndicator("Practive Fav"),
FavoriteList.class, null);
return rootView;
}
Run Code Online (Sandbox Code Playgroud)
}

这就是我的标签看起来的样子,我不知道如何设置这些标签的样式.在解释样式的大多数示例中,有一个XML格式的TabWidget,当我尝试在我的布局中添加它时它不起作用.
1)有人可以帮助我理解如何在Fragment中托管FragmenttabHost(mycode-来自某些教程)与在FragmentActivity中托管它有什么不同?
2)如何在代码中设置选项卡样式?
谢谢.
android android-style-tabhost android-fragments android-styles
我正在编写一个程序,我正在使用EditText并尝试应用填充,但它不起作用.
样式EditText
<style name="AppTheme.EditText" parent="android:Widget.EditText">
<item name="android:gravity">center</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">50dp</item>
<item name="android:background">@drawable/edit_border</item>
</style>
Run Code Online (Sandbox Code Playgroud)
应用于EditText
<EditText
android:id="@+id/editPartyDate"
style="@style/AppTheme.EditText"
android:hint="@string/reservation_date"
/>
Run Code Online (Sandbox Code Playgroud)
AndroidStudio
minSdkVersion 10
targetSdkVersion 21
Run Code Online (Sandbox Code Playgroud)
在设备上测试
Android Version - 4.1.2
Run Code Online (Sandbox Code Playgroud)
绘制/ edit_border.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#008f8471"/>
<stroke android:width="1dip" android:color="#ffffff" />
<corners android:radius="0dp"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
Run Code Online (Sandbox Code Playgroud)
码:
editDate = (EditText) view.findViewById(R.id.editPartyDate);
Run Code Online (Sandbox Code Playgroud) 我创建了一个自定义对话框主题,如下所示:
<style name="dialogLight" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowBackground">attr/theme_dialogBackground</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然而,当我运行应用程序时,dialog背景是默认设置(在一台设备上是透明的,在另一台设备上是黑色的).
但是,如果我更改android:windowBackground为android:background,android:background则会看到正确的行为,并且对话框中所有视图的默认背景将成为指定的值.
将android:windowBackground的值更改为@drawable或@color工作.
我知道android:windowBackground和之间有什么区别android:background,并且使用android:background不是我需要的,因为我只想改变窗口背景颜色.
那么为什么android:windowBackground不被应用呢?