0

我正在做一個編輯框看起來有了這個代碼更好工作的正確方法:Android的 - 重塑一個EditText上盒

<EditText 
     android:id="@+id/edittext" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dip" 
     android:layout_marginBottom="20dip" 
     android:padding="5dip" 
     android:singleLine="true" 
     android:background="@drawable/rounded_edittext" 
     android:hint="@string/hint" 
     android:textColor="#000"/> 

請注意:background屬性上面使用是一個形狀rounded_edittext象下面這樣:

<?xml version="1.0" encoding="utf-8"?> 

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

<item> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:padding="5dp" 
android:shape="rectangle" > 

<corners android:radius="5dp"/> 

<solid android:color="#ccc" /> 

</shape> 

</item> 

<item android:bottom="0.5dp"> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:padding="5dp" 
    android:shape="rectangle" > 

    <solid android:color="#FFFFFF" /> 

    <corners 
     android:bottomLeftRadius="5dp" 
     android:bottomRightRadius="5dp" 
     android:topLeftRadius="5dp" 
     android:topRightRadius="5dp" /> 

</shape> 
</item> 

</layer-list> 

應用此形狀後,edittext框看起來比以前漂亮,但我丟失了「I」輸入指示器。當我點擊編輯文本框並輸入內容時,沒有任何輸入指示符顯示,這使得感覺非常糟糕。我想知道這是否是重新設置編輯文本框的正確方法,或者是否有任何其他解決方法可以像這樣重新塑造框,但保留「I」輸入指示符。

+0

我沒有一個答案,但我也想知道發生了什麼,我可能會遇到這樣的問題。如果你輸入的東西它出現了嗎? – Giant

+0

@HakHak嗨是的,它顯示了我輸入的所有東西,除了輸入指示器... –

+0

只是一個猜測我真的不知道也許是因爲這個?試試000000 – Giant

回答

1

你需要寫OnClickListener上的EditText和您的活動試試這個代碼

EditText et = (EditText) findViewById(R.id.edittext); 

et.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 
    et.requestFocus(); 
    } 
}); 
+0

如果它適合你,不要將它標記爲已接受。 – akshay