問題描述
我正在啟動一個使用 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模板網!