2013-12-19 30 views
0

我有一個Sudoku網格圖像加載到我的應用程序中,但我遇到很多麻煩讓EditTexts出現在每個方塊中。當我運行該應用程序時,EditTexts中的數字幾乎不可見。我試過改變背景顏色和文字顏色,沒有任何改變。以編程方式創建基於數獨網格的EditTexts

/* PROGRAMATICALLY ADD EDITVIEWS via waiting for draw */ 
layout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() 
{ 

    public void onGlobalLayout() 
    { 
     layout.getViewTreeObserver().removeOnGlobalLayoutListener(this); 
     /* not used yet 
     int height = grid.getMeasuredHeight(); 
     int width = grid.getMeasuredWidth(); 
     int top = grid.getTop(); 
     //int bottom = grid.getBottom(); 
     int left = grid.getLeft(); 

     int square_height = height/9; 
     int square_width = width/9;*/ 

     for (int r = 0; r < 9; r++) 
     { 
      for (int c = 0; c < 9; c++) 
      { 
       text_boxes[r][c] = new EditText(getApplicationContext()); 
       text_boxes[r][c].setId(r+c); 
       text_boxes[r][c].setText("1"); 
       text_boxes[r][c].setInputType(InputType.TYPE_CLASS_NUMBER); 
       text_boxes[r][c].setFilters(new InputFilter[] {new InputFilter.LengthFilter(1)}); 
       RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 

       params.setMargins(c*10, r*50, 0, 0); 
       layout.addView(text_boxes[r][c], params); 
       text_boxes[r][c].setBackgroundColor(0x0FF00); 
      } 
     } 
    } 
}); 

回答

0

當您完成使用它時,您沒有移除偵聽器,因此它可以繼續被調用。

另外,關於EditText的顏色,只需更改EditTexts的背景,或者使用爲EditTexts設置默認背景的全局樣式,就可以將其更改爲任何您希望的內容。你甚至可以使用this tool

相關問題