我有在垂直線上顯示的相對佈局的一組edittexts的。默認情況下,他們之間有一個微小的餘量,雖然我沒有任何保證金設置。當我改變其中一個底色的背景顏色時,它的底部邊距會丟失,並且空間縮短到我認爲它下面的edittext的最小邊距。我試圖使用setPadding()
,但沒有結果。唯一有效的工作是setBackground()
,但這也改變了原來的顏色。的Android的EditText顏色變化破壞邊距
1
A
回答
0
相反setPadding的嘗試設置在XML緣至Edittexts。因爲您需要通過代碼設置邊距,您將不得不修改編輯文本的佈局參數。
在XML設置保證金應該解決您的問題。
+0
我試圖把它現在1DP,但它也有它的默認之一,你可以看到的EditText在屏幕上移動時,我改變顏色。事情是我希望它完全靜止,所以我會設置一個保證金,如果我可以擺脫它的默認保證金然後。 – Vali79
0
這個工作對我來說:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.9">
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#8A084B"
android:ems="10" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/editText1"
android:background="@android:color/black"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/editText2"
android:background="@android:color/darker_gray"
android:ems="10" />
並與他們之間的一些邊距:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.9">
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:background="#8A084B"
android:ems="10" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/editText1"
android:layout_marginBottom="2dp"
android:background="@android:color/black"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/editText2"
android:background="@android:color/darker_gray"
android:ems="10" />
如果你願意,你可以用id來撮合他們和android:layout_alignTop=
或底部。我希望它有幫助。
+0
它似乎沒有工作。 – Vali79
相關問題
- 1. Groupbox邊框顏色變化
- 2. 更改EditText的顏色android
- 3. ListView破壞我的變化
- 4. 圖標邊距/填充被破壞
- 5. 懸停時的邊框顏色變化
- 6. 變化的datagridview cellstyle邊框顏色
- 7. 更改的EditText邊框顏色
- 8. 更改文字的顏色,無邊框顏色變化
- 9. TextInputLayout改變的EditText顏色爲紅色
- 10. Android ListView顏色變化
- 11. android背景顏色變化
- 12. Android按鈕顏色變化
- 13. 的Android變化的TextView的顏色
- 14. Intellij - 左邊距中的CSS顏色框
- 15. 更改text_field_tag的邊距/背景顏色
- 16. 如何設置QGridLayout邊距的顏色?
- 17. CSS - 包含邊距的背景顏色
- 18. Android的ListView的文本顏色變化
- 19. 變化的android TextView的顏色
- 20. 如何更改android中edittext邊框的選定顏色?
- 21. Android:是否可以動態更改EditText的邊框顏色?
- 22. 如何更改Android中的Edittext顏色邊框
- 23. 邊框顏色變化沒有輸入
- 24. 改變顏色的EditText的下劃線
- 25. 在Android中的EditText不同的顏色
- 26. Android的背景顏色變化
- 27. 顏色變化的算法錯誤 - Android
- 28. 與顏色變化在旋轉的Android
- 29. Android的listview項顏色變化
- 30. Edittext更改邊框顏色始終onclick
你可以在這裏添加您的代碼?這可能會提供一個更好的主意。 –
我用這個來改變顏色:'tari.setBackgroundColor(Color.parseColor(「#2aff00」));'這恢復到這是我在一開始保存在一個可繪製原始背景:'tari.setBackground( backs [0]);' – Vali79
'setPadding()'會在內部增加空間。你爲什麼不簡單地爲EditText設置一個邊距? –