Android的不同背景的EditText使用的形状,或选择列表中的不同状态不同、形状、背景、状态

2023-09-05 03:21:38 作者:Faerie(妖精)

我开始一个新的应用程序,我用ActionBarSherlock和放大器; HoloEverywhereLib。我分和放大器;目标的SDK是相同的(10 / 2.3.3)。这仅仅是这样我也可以很快移植到亚马逊的Kindle和放大器; BB10使用了Android的运行时他们(已使用此设置的其他应用程序,它的工作没有问题)。在这期间应用程序应该尽可能靠近ICS / JB看起来越好。

I'm starting a new app where I use ActionBarSherlock & HoloEverywhereLib. My min & target SDK are the same (10/2.3.3). This is just so I can also quickly port it to Amazon Kindle & BB10 using the android runtime they have (already used this setup for another app and it worked without issue). All the while the app should have as close to ICS/JB look as possible.

有关我EditTexts虽然,我给他们一个Girgerbread /的iOS(圆角,但没有阴影)看他们

For my EditTexts though, I'm giving them a Girgerbread/iOS (round corners, but no shadows) look to them

有人向我提到了几个星期前抢到了可绘制的姜饼,并利用它们来我EditTexts。但我开始用另一种答案,我发现这里的S / O,很简单的:

Someone mentioned to me a few weeks ago to grab the drawables for Gingerbread and use them to my EditTexts. but i starting using another answer I found here at S/O, very simple:

<EditText
 background:"@drawable/edittext_round_white"
 ..../>

&放大器;我edittext_round_white.xml:

& my edittext_round_white.xml:

 <?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android" 
  android:shape="rectangle"
  >
  <corners android:radius="8dp"/>
<stroke android:width="1dp"
    android:color="#444"/>
<solid android:color="#FFFFFF" />
  </shape>

现在,当我运行的应用程序,两件事情是不对的。

Now, when I run the app, two things are not right

一)不存在焦点在所有(我知道我需要实现这一点,这是问题的点)

a) there is no 'focus' at all (I'm aware I need to implement this, it's the point of the question)

b)该光标不会在我的EditText出现在所有(在灰色垂直线暗示到在的EditText输入被引导)

b) the cursor does not appear at all in my edittext (the gray vertical line hinting at to where in the edittext the input is directed)

有关一) 我想我已经使用某种选择或列表中,对不对?怎么样?我是新来的造型在Android和任何帮助,将AP preciated。我要改变的唯一的事情就是描边颜色。

For a) I assume I've to use some sort of selector or list, right? how? I'm new to styling in android and any help would be appreciated. The only thing I'm going to change is the stroke color.

有关二)我怎样才能使光标显示出来?

For b) how can I make cursor show up?

任何提示/链接/等这里非常欢迎!

Any hints / links / etc here are very much welcomed!

推荐答案

我建议使用NinePatch图像来定制您的EditText。这里去根据我的code的例子:

I suggest to use NinePatch images to customize your EditText. Here goes an example based on my code:

选择:

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

使用选择您在code用同样的方式,将其设置为你的EditText的背景。

Use selector the same way you used in your code, set it to background of your EditText.

图片:

 twitter_im_edittext_focused.9.png

twitter_im_edittext_focused.9.png

 twitter_im_edittext_normal.9.png

twitter_im_edittext_normal.9.png

更多关于NinePatch图像,你可以找到这里。

More about NinePatch images you can found here.

希望它帮助。

 
精彩推荐