我正在启动一个使用 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
几周前有人向我提到要获取 Gingerbread 的可绘制对象并将它们用于我的 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) 根本没有焦点"(我知道我需要实现这一点,这是问题的重点)
a) there is no 'focus' at all (I'm aware I need to implement this, it's the point of the question)
b) 光标根本没有出现在我的编辑文本中(灰色垂直线提示输入在编辑文本中的位置)
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 样式的新手,任何帮助将不胜感激.我唯一要改变的是描边颜色.
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.
对于 b) 我怎样才能让光标出现?
For b) how can I make cursor show up?
非常欢迎任何提示/链接/等!
Any hints / links / etc here are very much welcomed!
我建议使用 NinePatch 图片来自定义你的 EditText.这是基于我的代码的示例:
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>
使用与代码中相同的方式使用选择器,将其设置为 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.
希望对你有帮助.
这篇关于Android 使用形状、选择器或列表的不同状态的不同 EditText 背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
EditText:禁用文本选择处理程序单击事件上的粘贴EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本选择处理程序单击事件上的粘贴/替换菜
2.3 上带有完成 SoftInput 操作标签的多行 EditTextMultiline EditText with Done SoftInput Action Label on 2.3(2.3 上带有完成 SoftInput 操作标签的多行 EditText)
如何在 Android 中检测向左或向右滑动?How to detect the swipe left or Right in Android?(如何在 Android 中检测向左或向右滑动?)
防止在Android中的屏幕旋转对话框解除Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋转对话框解除)
如何处理 ImeOptions 的完成按钮点击?How do I handle ImeOptions#39; done button click?(如何处理 ImeOptions 的完成按钮点击?)
您如何将 EditText 设置为仅接受 Android 中的数值How do you set EditText to only accept numeric values in Android?(您如何将 EditText 设置为仅接受 Android 中的数值?)