找到你要的答案

Q:Material design inverse spinner/edittext theme using AppCompat

Q:材料设计的逆旋转/编辑主题使用appcompat

I'm having issues creating a Material Design app with the AppCompat v21 theme. First I have my app theme using the AppCompat light with dark actionbar.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Main theme colors -->
    <!--   your app branding color for the app bar -->
    <item name="colorPrimary">@color/theme_color</item>
    <!--   darker variant for the status bar and contextual app bars -->
    <item name="colorPrimaryDark">@color/theme_color_dark</item>
    <!--   theme UI controls like checkboxes and text fields -->
    <item name="colorAccent">@color/theme_color_accent</item>
</style>

The color branding for my app is quite dark which is why I use the DarkActionBar variant. My problem is that I have a couple layouts where I'd like to put a Spinner and an EditText inside a layout where the background is my theme_color which is dark. This results in a Spinner/EditText with black color on a dark background. How can I make the style/theme of these controls use the Dark variant so they show up with white text instead of black text. Even worse than that, I need the spinner to show white text but dropdown items of the spinner to show the light version.

我有问题,创造一个与appcompat V21主题材料的设计应用。首先我有我的应用程序使用的光与黑暗的主题appcompat ActionBar。

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Main theme colors -->
    <!--   your app branding color for the app bar -->
    <item name="colorPrimary">@color/theme_color</item>
    <!--   darker variant for the status bar and contextual app bars -->
    <item name="colorPrimaryDark">@color/theme_color_dark</item>
    <!--   theme UI controls like checkboxes and text fields -->
    <item name="colorAccent">@color/theme_color_accent</item>
</style>

色彩的品牌我的应用程序是相当黑暗的这就是为什么我用darkactionbar变异。我的问题是,我有一对夫妇的布局,我想把一个旋转和内部布局,背景是我的theme_color是黑暗一个EditText。这样的结果在一个黑色背景上的黑色旋转/编辑。我怎样才能使这些控件的样式/主题使用黑色的变体,以便它们显示白色文本而不是黑色文本。更糟糕的是,我需要微调显示白色文字但下拉的微调显示光版项目。

answer1: 回答1:

I'm using a Spinner inside a Toolbar with dark background and remembered that the Google I/O Android App does the same, so I looked at its styles - more specifically, the ActionBarThemeOverlay here.

After I used the below attributes on my theme, my Spinner background color (the "arrow") changed:

<item name="colorControlNormal">#fff</item>
<item name="colorControlHighlight">#3fff</item>

colorControlHighlight is the color when the user presses the Spinner. I didn't test on an EditText, though.

我用一个旋转在一个黑暗的背景工具栏和记得谷歌开发者大会Android应用一样,所以我看着它的风格,更特别的是,这里的actionbarthemeoverlay。

我用下面的我的主题,我飞旋的背景颜色(“箭”)改变:

<item name="colorControlNormal">#fff</item>
<item name="colorControlHighlight">#3fff</item>

colorcontrolhighlight色是当用户按下旋转。我没有一个EditText没有测试,但。

answer2: 回答2:

So, you're looking for a way to apply a different theme to select views. There's no xml-only way to do that for most elements (except Toolbar, which you already know)

You'll have to inflate the views manually, using a ContextThemeWrapper:

ContextThemeWrapper wrapper = new ContextThemeWrapper(getActivity(),
    R.style.Theme_AppCompat); // The dark one
LayoutInflater footPump = LayoutInflater.from(getActivity()).cloneInContext(wrapper);
// Note null as second argument -- if you pass in parent view, theme will
// be taken from the parent
Spinner spinner = (Spinner) footPump.inflate(R.layout.spinner, null);

to have the layout resource for the inflater, just create a single-view xml file:

<!-- res/layout/spinner.xml -->
<?xml version="1.0" encoding="utf-8"?>
<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

So, you're looking for a way to apply a different theme to select views. There's no xml-only way to do that for most elements (except Toolbar, which you already know)

你要将视图手动,使用contextthemewrapper:

ContextThemeWrapper wrapper = new ContextThemeWrapper(getActivity(),
    R.style.Theme_AppCompat); // The dark one
LayoutInflater footPump = LayoutInflater.from(getActivity()).cloneInContext(wrapper);
// Note null as second argument -- if you pass in parent view, theme will
// be taken from the parent
Spinner spinner = (Spinner) footPump.inflate(R.layout.spinner, null);

有打气筒布局资源,只是创建一个视图的XML文件:

<!-- res/layout/spinner.xml -->
<?xml version="1.0" encoding="utf-8"?>
<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
answer3: 回答3:

How about this..

make a style for you widget, ex:

<style name="CustomEditText" parent="android:Widget.EditText">
      <item name="android:textColor">@color/red</item>
</style>

then in your xml add this attribute to your EditText

style="@style/CustomEditText"

这样好了。

制作一个风格为您的小工具,EX:

<style name="CustomEditText" parent="android:Widget.EditText">
      <item name="android:textColor">@color/red</item>
</style>

然后在你的XML添加属性到你的编辑

style="@style/CustomEditText"
android  android-edittext  spinner  appcompat  material-design