2017-03-02 18 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