android-如何更改我的编辑文本和微调器的样式

问题描述 投票:1回答:4

这些是我的微调器和编辑文本的样子:

这些是我在其他地方看到的微调器和编辑文本,我喜欢它们:

如何更改我的edittext和微调器以查看第二个图像?

无论如何我正在使用app compact

谢谢

android android-edittext android-spinner android-theme android-styles
4个回答
1
投票

为Spinner设置背景和EditText将帮助您弄清楚它。

<Spinner  android:id="@+id/spinner"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/spinner_bg"/>

<EditText  android:id="@+id/edittext"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/edittext_bg"/>
</LinearLayout>

1
投票

到现在为止,我可以为您指导EditText部分..

像这样定义你的样式drawable ..

RES /抽拉/ edit_text_style.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
  <item>
      <shape >
          <solid android:color="@color/wine_red" />
      </shape>
  </item>

  <!-- main color -->
  <item android:bottom="1.5dp"
      android:left="1.5dp"
      android:right="1.5dp">
      <shape >
          <solid android:color="@color/white" />
      </shape>
  </item>

  <!-- draw another block to cut-off the left and right bars -->
  <item android:bottom="5.0dp">
      <shape >
          <solid android:color="@color/white" />
      </shape>
  </item>
  </layer-list>

现在在你的EditText中定义相同的..

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.vivektest.MainActivity" >

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <EditText 
       android:background="@drawable/edit_text_style"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/et_main"
        android:imeOptions="actionSearch"
        android:singleLine="true"
        />

</RelativeLayout>

希望能帮助到你!


1
投票

这是您可以用于所有视图的最佳工具,非常感谢@Jérôme Van Der Linden

Android Holo颜色生成器允许您轻松地为您的Android应用程序创建具有自己颜色的EdiText或spinner等Android组件。它将生成所有必需的九个补丁资源以及相关的XML drawable和样式,您可以将它们直接复制到项目中。

http://android-holo-colors.com/

更新1

这个域似乎已过期,但项目是开源的,你可以在这里找到

https://github.com/jeromevdl/android-holo-colors

试试吧

这张图片放在EditText的背景中

android:background="@drawable/textfield_activated"


更新2

对于API 21或更高版本,您可以使用android:backgroundTint

<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Underline color change"
        android:backgroundTint="@android:color/holo_red_light" />

更新3现在我们支持AppCompatEditText

注意:我们需要使用app:backgroundTint而不是android:backgroundTint

<android.support.v7.widget.AppCompatEditText
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:hint="Underline color change"
    app:backgroundTint="@color/blue_gray_light" />

0
投票

微调器样式的解决方案:使用自定义布局为您的微调器创建自定义适配器。

Spinner spinner = (Spinner) findViewById(R.id.pioedittxt5);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
        R.array.travelreasons, R.layout.simple_spinner_item);
adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
R.layout.simple_spinner_item

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="@style/spinnerItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee" />
R.layout.simple_spinner_dropdown_item

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="@style/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/dropdownListPreferredItemHeight"
    android:ellipsize="marquee" />
In styles add your custom dimensions and height as per your requirement.

 <style name="spinnerItemStyle" parent="android:Widget.TextView.SpinnerItem">

  </style>

  <style name="spinnerDropDownItemStyle" parent="android:TextAppearance.Widget.TextView.SpinnerItem">

  </style>

取自here

© www.soinside.com 2019 - 2024. All rights reserved.