2013-09-03 5 views
0

텍스트를 클릭하여 레이아웃에서 TextView를 사용하고 있습니다. 색상을 변경하고 싶습니다. text.setTextColor(Color.parseColor("#FFFFFF"));을 사용할 수 있지만 문제는 색상이 저장되지 않고 색상을 뒤로 밀면됩니다. 변경되지 않습니다. 어떻게해야합니까?안드로이드에 텍스트 색상 저장

답변

3

당신은 당신이 textView

http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList

에 선택기를 만들 수 있습니다 또는 당신은 당신 button http://developer.android.com/reference/android/view/View.OnTouchListener.html

ontouchlistener을 등록 할 수 있으며, MotionEvent의 도움으로 당신의 행동의 스위치 케이스를 만들 수 있습니다 을 (를) 누르고있을 때 버튼을 놓을 때

http://developer.android.com/reference/android/view/MotionEvent.html

4
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 

<item android:state_pressed="true" 
    android:color="#ffffffff"/> <!-- pressed --> 
<item android:state_focused="true" 
    android:color="#ff0000ff"/> <!-- focused --> 
<item android:color="#ff000000"/> <!--default --> 

</selector> 
+0

확인 : android.view.selector 로더 dalvik.system.PathClassLoader [/data/app/com.emergencycalls-1.apk]' –

+0

@ somethingall ur는 무엇을 사용하는 것처럼 – Kirti

+0

을 사용하지 않으십니까? –

0

음!

단추의 배경을 정의한 것과 마찬가지로 모든 4 가지 상태에 대해 텍스트 색을 정의 할 수 있습니다. 예를 들면 :

파일 이름 : /res/color/text_color.xml

XML 파일 입술에 저장/드로어 블/사진 button.xml :

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_enabled="false" android:color="#440000"/> 
<item android:state_focused="true" android:color="#004400"/> 
<item android:state_pressed="true" android:color="#000044"/> 
<item android:color="#444"/> 
</selector> 

이 (당신의 단추 스타일에이 파일을 가지고 \ 고해상도 \ 값이 같은 \ styles.xml) :

<style name="button_text" parent="@android:style/Widget.Button"> 
<item name="android:textColor">@color/text_color.xml</item> <!-- Here is specified text color -- > 
</style> 

는 이제 버튼에이 스타일을 추가

<Button 
android:id="@+id/button1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
style="@style/button_text"> 
</Button> 
012 3,516,

상세 것이이 오류 'java.lang.ClassNotFoundException가 발생 this

+0

를 표시하지 않을 경우 –

+0

@AmirSadeghsorry 질문을 이해하지 못했습니다. 이제 답변을 업데이트했습니다. 확실하게 도움을 드리겠습니다. –

+0

@AmirSadeghplz가 작동하는지 여부를 알려주세요. –

관련 문제