2014-02-18 2 views
3

나는 edittext가있는 간단한 레이아웃을 가지고 있습니다. 나는 색상EditText 문제의 배경색 변경

<EditText 
     android:id="@+id/et" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:background="@android:color/white" /> 

글고 향상에 포커스 때 그런 이상한 일이 발생, 레이아웃 변경의 배경 색상에 EditText의 배경을 설정

(!).

는 동적으로 배경색을 변경해야하고, 나는 호출 한 후 같은 결과를 가지고

subject.setBackgroundColor(Color.parseColor(mycolor)); 

나는 또한 다음과 같은 방법을 시도했다 :

subject.setBackground(new ColorDrawable(Color.parseColor(mycolor))); 

결과는 동일했다.

기본적으로 런타임에 Edittext의 배경색을 변경하고 싶습니다.

+0

사용 선택기 ... http://stackoverflow.com/questions/14542557/android-different-edittext-backgrounds-for-different-states-using-shapes-select – ASP

+0

http://stackoverflow.com/questions/11275779/edittext-drawable-background-for-each-state – ASP

+0

@ASP 원격 서버에서 색상을 얻으므로 색상을 동적으로 변경하고 싶습니다. – user1940676

답변

2

솔루션은 배경을 잡고 null로 EditText 배경을 설정할 부모 레이아웃을 추가했다.

나는 그 해결책을 좋아하지 않지만 제대로 작동합니다.

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/white" > 

    <EditText 
     android:id="@+id/et" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@null" /> 
</LinearLayout> 
+0

감사합니다. 이 답변은 비슷한 문제를 해결하는 데 도움이되었습니다. – kord

0

는 시도 이것 ::

String myHexColor = "#CC2233";// color u get from webserver 
EditText myView = (EditText) findViewById(R.id.myEditText); 
myView.setBackGroundColor(Color.pasrsehexString(myHexColor)); 
+0

pasrsehexString (String) 메서드는 Color 유형에 대해 정의되어 있지 않습니다. parseColor는 내가 사용하는 것으로 실제로 작동합니다. – user1940676

+0

이 작품을 생각합니다 : : myView.setBackgroundColor (Color.parseColor ("# 636161")); – ASP

+0

내가 이미 사용하고있는 것입니다 – user1940676