2013-04-22 3 views
1

내 문제는 edittext 필드에 검은 색 커서가있는 alertdialog가 있다는 것입니다. 이 색상을 흰색으로 변경하고 싶습니다. 다음과 같이 편집 문구의 색을 흰색으로 쉽게 설정할 수 있습니다.경고 대화 상자에서 편집 텍스트의 커서 색 변경

edittext.setTextColor(Color.WHITE); 

문제는 커서 색이 여전히 검은 색입니다. 그래서 몇 가지 조사를하고이 코드를 추가하여 XML 파일의 커서 색상을 변경하는 방법에 대한 몇 가지 기사를 발견

android:textCursorDrawable="@drawable/white_cursor" 

white_cursor.xml은 다음과 같습니다을 : 그래서 나는 글고 치기를 생성

<?xml version="1.0" encoding="utf-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <size android:width="1dp"/> 
    <solid android:color="#FFFFFF" /> 
    </shape> 

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

그러나 쇼가() 때 - 메소드가 호출되고, 응용 프로그램이 충돌 : 기능 - 그리고 XML 파일의 findById 메소드()을한다. 누구든지 내 코드에서 커서 색상을 변경하거나 오류없이 구현하는 방법을 알고 있습니까? 들으

편집 1 개에 AlertDialog 코드 :

input = (EditText) findViewById(R.id.eText); 
    InputFilter[] filters = new InputFilter[1]; 
    filters[0] = new InputFilter.LengthFilter(20); 
    input.setFilters(filters); 
    input.setTextColor(Color.WHITE); 

    alertbuilder = new AlertDialog.Builder(this,AlertDialog.THEME_HOLO_DARK); 
    alertbuilder.setTitle("Enter the levelname!"); 
    alertbuilder.setMessage("To change the levelname after it has been created, tap and hold the icon of the level."); 

    alertbuilder.setView(input); 

    alertbuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
    public void onClick(final DialogInterface dialog, final int whichButton) { 
    Editable value = (Editable) input.getText(); 
     // Do stuff 
     dialog.dismiss(); 

     } 

    }); 

    alertbuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int whichButton) { 
      dialog.dismiss(); 
     } 
    }); 
    alertadd=alertbuilder.create(); 
    alertadd.show(); //crash here 

EDIT2의 로그 캣 :

04-22 20:00:34.217: D/OpenGLRenderer(2475): Flushing caches (mode 0) 
04-22 20:00:37.216: D/Input(2475): VelocityTracker: int datax = 15 
04-22 20:00:37.216: D/Input(2475): VelocityTracker: int m_velocity_magnify_x = 1.500000 
04-22 20:00:37.216: D/Input(2475): VelocityTracker: int datay = 20 
04-22 20:00:37.216: D/Input(2475): VelocityTracker: int m_velocity_magnify_y = 2.000000 

나는 나의 로그 캣에서 오류 메시지가 없습니다 얻을. 찾을 수없는 소스 - - 실제로 클래스 파일 편집기 얻는 문제가 여기에 오류 내가 생각

+1

게시하여 경고 대화 상자 코드 ... – Pragnani

+0

포스트 로그 캣 오류를

는 당신이 파일 dialog_content.xml을 작성하는 것이 좋습니다. – TronicZomB

+0

귀하의 edittext 레이아웃의 일부입니다 ..? 즉, 현재 Activity에 대해 setContentView에 의해 설정된 레이아웃의 일부입니까? – Pragnani

답변

0

을 :

input = (EditText) findViewById(R.id.eText); 

당신은 설정할 수 없습니다 대화 내용 등 EditText이 경우 활동/조각 레이아웃의 그 부분 .

<?xml version="1.0" encoding="utf-8"?> 
<EditText 
    style="@style/yourEditTextStyle" 
    android:id="@+id/myEditTextId" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" /> 

그리고이 방법으로 EditText을 만드는 :

input = (EditText) LayoutInflater.from(this).inflate(R.layout.dialog_content, null); 
+0

그래,이 말이 잘 들린다. 나는 실제로 문제를 relativelayout에서 edittext를 제거하여 해결했지만,이 솔루션은 좀 더 탄탄한 방법입니다 ... 커서 색상을 프로그래밍 방식으로 변경하는 방법이없는 이유는 아직 궁금합니다. – Commander3000

관련 문제