本文介绍了风格的Andr​​oid微调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的Andr​​oid应用程序多一点时尚,并已取得了一些进展,但微调的下拉是给我找麻烦。我有一个截图显示问题:

I'm trying to get my android app a bit more stylish and have made some progress but the spinner dropdown are giving me trouble. I've got a screenshot to show you the problem:

我要的是在后台的白色盒子是透明的,因为在相同的灰色覆盖于背部屏幕作为屏幕的下拉列表之外的其余部分。

What I want is the white box in the background to be transparent, as in the same grey overlay over the back screen as the rest of the screen outside the dropdown.

Android 4.0的,API的15,如果我没有记错。

Android 4.0, API 15 if I recall correctly.

按照要求这里是我如何做到这一点至今。这些片段,我认为是相关的,但我可能会错过一些东西。

As requested here's how I do it so far. These are snippets I think are relevant but I might have missed something.

下面是在XML的微调:

Here's the xml for spinner:

<Spinner
    android:id="@+id/edit_countrySpinner"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:entries="@array/edit_countryArray"
    android:gravity="center"
    android:prompt="@string/country_prompt" />

在我的价值观/ style.xml。如果我改变背景颜色在这里的对话框不改变的背景下,但背景其余全部为好。我还没弄清楚如何强制更改下拉对话框的背景。

In my values/style.xml. If I change the color of the background here the background in the dialog do change, but all the rest of the backgrounds as well. I haven't figure out how to jus change the background in the dropdown dialog.

<style name="appcin" parent="@android:style/Theme.NoTitleBar.Fullscreen">
    <item name="android:spinnerStyle">@style/spinnerStyle</item>
    <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
    <item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item> -->
    <item name="android:background">#FFFFFF</item>
</style>
<style name="spinnerStyle">
    <item name="android:background">@drawable/pink_white_dropdown</item>
    <item name="android:clickable">true</item>
</style>
<style name="SpinnerItem">
    <item name="android:textColor">#993399</item>
    <item name="android:background">@drawable/pink_white_dropdown</item>
    <item name="android:maxHeight">10dip</item>
</style>
<style name="SpinnerDropDownItem">
    <item name="android:textColor">#993399</item>
    <item name="android:background">#FFFFFF</item>
</style>

我试着将其加入应用程序的主题,但他们没有什么不同,背景仍然是白色的。

I've tried adding this to the app theme but none of them made any difference, the background was still white.

<...theme....>
   <item name="android:dropDownListViewStyle">@style/DropDownStyle</item>
   <item name="android:dropDownSpinnerStyle">@style/DropDownStyle</item>
   <item name="android:dropDownSelector">@style/DropDownStyle</item>
</... theme ...>
<style name="DropDownStyle">
    <item name="android:background">#FFF000</item>
    <item name="android:popupBackground">#FFF000</item>
    <item name="android:cacheColorHint">#FFF000</item>
</style>

在绘制/ pink_white_dropdown,只是表示所有情况下相同的图像。 pink_white_arrow是我做了一个9patch图像。有很多导游,这里有一个我发现30秒的谷歌

In drawable/pink_white_dropdown, just showing the same image for all the cases. pink_white_arrow is a 9patch image I've made. There are lots of guides, here's one I found by 30sec on google.

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_window_focused="false" android:state_enabled="true"
      android:drawable="@drawable/pink_white_arrow"/>
  <item android:state_window_focused="false" android:state_enabled="false"
      android:drawable="@drawable/pink_white_arrow"/>
  <item android:state_pressed="true" 
      android:drawable="@drawable/pink_white_arrow"/>
  <item android:state_pressed="false" 
      android:drawable="@drawable/pink_white_arrow"/>
  <item android:state_focused="true" android:state_enabled="true" 
      android:drawable="@drawable/pink_white_arrow"/>
  <item android:state_enabled="true" 
      android:drawable="@drawable/pink_white_arrow"/>
  <item android:state_focused="true" 
      android:drawable="@drawable/pink_white_arrow"/>
  <item 
      android:drawable="@drawable/pink_white_arrow"/>
</selector>

在某处这些文件我想的东西应该是透明的,但我不知道在哪里。

Somewhere in these files I figure something should be made transparent, but I don't know where.

推荐答案

删除 SpinnerStyle 背景属性。

删除这样的:

<style name="spinnerStyle">
    <item name="android:background">@drawable/whitish_rectangle</item>
</style>

这是什么吸引背景白色矩形。

which is what draws the background white rectangle.

建立在code你的问题,这里是你如何风格你的微调一个基本的例子:

Building on the code in your question, here is a basic example on how you can style your Spinner:

styles.xml 文件设置样式为 SpinnerItem SpinnerDropDownItem

<resources>
    <style name="customtheme" parent="@android:style/Theme.Light">
        <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
        <item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
    </style>
    <style name="SpinnerItem">
        <item name="android:textColor">#993399</item>
        <item name="android:background">@drawable/my_rectangle</item>
    </style>
    <style name="SpinnerDropDownItem">
        <item name="android:textColor">#993399</item>
        <item name="android:background">@drawable/my_rectangle</item>
    </style>
</resources>

有关测试,我创建了一个鲜艳的绘制形状,叫做 my_rectangle.xml 。用自己的绘制替换这样的:

For testing, I've created a bright-colored drawable shape, called my_rectangle.xml. Replace this with your own drawable:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#ff0000" />
    <stroke
        android:width="1dp"
        android:color="#888888" />
</shape>

添加微调活动的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:padding="40dip">
    <Spinner
        android:id="@+id/edit_countrySpinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:entries="@array/location_names"/>
</LinearLayout>

这将产生:

没有白色方形的背景。

这篇关于风格的Andr​​oid微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 03:10