2017-03-02 61 views
0

幫助!我有一組edittext字段在(LinearLayout),我啓用和禁用編程。 當我啓用和禁用字段screenshot時,edittexts寬度沒有問題。問題就來了edittexts啓用後,要麼android所有的edittext寬度在方向變化和焦點上的變化

  1. 方向改變或

  2. user clicks to focus on any of the edittexts then the widths of ALL the edittexts become 1 character.

這裏是我的editexts的一個代碼。其餘都是一樣的,只有id是不同的。

  <EditText 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/purchase_price" 
       android:imeOptions="flagNoExtractUi|actionNext" 
       android:maxLines="1" 
       android:singleLine="true" 
       android:inputType="numberDecimal"> 

這裏是啓用字段的代碼。

public void onCreate(Bundle savedInstanceState) { 


    enabledEdittext = mPurchasePrice.getBackground(); 
    disabledEditext = ContextCompat.getDrawable(this, R.drawable.disabled_edittext); 
    . 
    . 
    . 
    mPurchasePrice.setBackground(enabledEdittext); 
    } 

回答

0

可以使用EditText.setFocusable(false)來取消編輯 EditText.setFocusableInTouchMode(真),以使編輯;

而不是改變背景。

+0

我改變了背景,因爲客戶的要求是當禁用字段時刪除edittext下的行。 – vyxf