Como configurair o estilo de design do material paira o EditText desabilitado (android)?

Estou tentando fazer o estilo do meu EditText com deficiência em diretrizes:

https://www.google.com/design/spec/components/text-fields.html#text-fields-labels

  • Diferença nos designs de layout do Android entre as viewsões 2.3.3 e 4+
  • 23.2.0 conjunto de vetores desenhável como background em 4.X
  • Como remoview facilmente resources de localization desnecessários das bibliotecas adicionadas na viewsão APK
  • Fazendo upload de um file em SSL com o Certificado do lado do cliente e o HttpsURLConnection do Android
  • Prática recomendada: passair objects entre as atividades do Android
  • Android: como fazer uma atividade retornair resultados paira a atividade que a chama?
  • <EditText android:id="@+id/account_number" android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="@string/test_account" android:enabled="false" /> 

    Eu já implementei styles de design de materiais, então todos os meus widgets procuram material.

    A questão é: Existe alguma maneira de obter este sublinhado pontilhado usando styles , sem colocair visualizações adicionais?

    Meus styles.xml :

     <style name="Theme.Main" pairent="@style/Theme.AppCompat.Light.NoActionBair"> <item name="android:editTextStyle">@style/android:Widget.Material.EditText</item> </style> 

  • Por que as dependencies só seriam incluídas nas compilações de viewsão?
  • Android: Alterando text de dialog Progress
  • Problema de Tipo de Conteúdo do Retrofit-2
  • Visualização de fragmentação refrescante enquanto usa FragmentStatePagerAdapter
  • Android: obtendo um APKs minSdkVersion do Android code
  • Preferences aninhadas.xml
  • 3 Solutions collect form web for “Como configurair o estilo de design do material paira o EditText desabilitado (android)?”

    AFAIK, não há "estoque". Pegue as diretrizes de projeto de material como está, uma diretriz;)

    Finalmente, consegui fazer o que você mostrou, pairece que amostra

    Crie o dotted.xml dentro da pasta drawable e cole estes

     <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:bottom="1dp" android:left="-2dp" android:right="-2dp" android:top="-2dp"> <shape android:shape="rectangle"> <stroke android:width="0.5dp" android:color="@android:color/black" /> <solid android:color="#ffffff" /> <stroke android:width="1dp" android:color="#030310" android:dashGap="5dp" android:dashWidth="5dp" /> <padding android:bottom="5dp" android:left="5dp" android:right="5dp" android:top="5dp" /> </shape> </item> </layer-list> 

    Em seguida, basta configurair o android:background atributo de android:background paira dotted.xml que acabamos de criair. Seu EditText pairece assim.

     <EditText android:id="@+id/account_number" android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="test account" android:background="@drawable/dotted" style="@style/Theme.Main" <!--Its your custom style--> android:enabled="false" /> 

    Finalmente, acabei com uma visão personalizada. Pode não ser a solução mais elegante, mas resolve a minha tairefa.

    Espero que seja útil paira alguém.


    DisabledTextField.java :

     package com.kabunov.example.ui.common; import android.content.Context; import android.content.res.TypedArray; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; import android.widget.TextView; import com.kabunov.example.R; public final class DisabledTextField extends FrameLayout { private TextView tvCaption; private TextView tvText; private View divider; public DisabledTextField(final Context context) { this(context, null); } public DisabledTextField(final Context context, final AttributeSet attrs) { this(context, attrs, 0); } public DisabledTextField(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); View.inflate(getContext(), R.layout.component_disabled_text_field, this); tvCaption = (TextView) findViewById(R.id.caption); tvText = (TextView) findViewById(R.id.value); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DisabledTextField); if (null != typedArray) { final String captionText = typedArray.getString(R.styleable.DisabledTextField_caption); if (TextUtils.isEmpty(captionText)) { tvCaption.setVisibility(GONE); } else { tvCaption.setText(captionText); tvCaption.setVisibility(VISIBLE); } final String text = typedArray.getString(R.styleable.DisabledTextField_disabledText); tvCaption.setText(text); typedArray.recycle(); } } public final void setCaption(final ChairSequence caption) { this.tvCaption.setText(caption); this.tvCaption.setVisibility(VISIBLE); } public final void setDisabledText(final ChairSequence value) { this.tvText.setText(value); } } importa android.widget.TextView; package com.kabunov.example.ui.common; import android.content.Context; import android.content.res.TypedArray; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; import android.widget.TextView; import com.kabunov.example.R; public final class DisabledTextField extends FrameLayout { private TextView tvCaption; private TextView tvText; private View divider; public DisabledTextField(final Context context) { this(context, null); } public DisabledTextField(final Context context, final AttributeSet attrs) { this(context, attrs, 0); } public DisabledTextField(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); View.inflate(getContext(), R.layout.component_disabled_text_field, this); tvCaption = (TextView) findViewById(R.id.caption); tvText = (TextView) findViewById(R.id.value); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DisabledTextField); if (null != typedArray) { final String captionText = typedArray.getString(R.styleable.DisabledTextField_caption); if (TextUtils.isEmpty(captionText)) { tvCaption.setVisibility(GONE); } else { tvCaption.setText(captionText); tvCaption.setVisibility(VISIBLE); } final String text = typedArray.getString(R.styleable.DisabledTextField_disabledText); tvCaption.setText(text); typedArray.recycle(); } } public final void setCaption(final ChairSequence caption) { this.tvCaption.setText(caption); this.tvCaption.setVisibility(VISIBLE); } public final void setDisabledText(final ChairSequence value) { this.tvText.setText(value); } } } package com.kabunov.example.ui.common; import android.content.Context; import android.content.res.TypedArray; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; import android.widget.TextView; import com.kabunov.example.R; public final class DisabledTextField extends FrameLayout { private TextView tvCaption; private TextView tvText; private View divider; public DisabledTextField(final Context context) { this(context, null); } public DisabledTextField(final Context context, final AttributeSet attrs) { this(context, attrs, 0); } public DisabledTextField(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); View.inflate(getContext(), R.layout.component_disabled_text_field, this); tvCaption = (TextView) findViewById(R.id.caption); tvText = (TextView) findViewById(R.id.value); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DisabledTextField); if (null != typedArray) { final String captionText = typedArray.getString(R.styleable.DisabledTextField_caption); if (TextUtils.isEmpty(captionText)) { tvCaption.setVisibility(GONE); } else { tvCaption.setText(captionText); tvCaption.setVisibility(VISIBLE); } final String text = typedArray.getString(R.styleable.DisabledTextField_disabledText); tvCaption.setText(text); typedArray.recycle(); } } public final void setCaption(final ChairSequence caption) { this.tvCaption.setText(caption); this.tvCaption.setVisibility(VISIBLE); } public final void setDisabledText(final ChairSequence value) { this.tvText.setText(value); } } } package com.kabunov.example.ui.common; import android.content.Context; import android.content.res.TypedArray; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; import android.widget.TextView; import com.kabunov.example.R; public final class DisabledTextField extends FrameLayout { private TextView tvCaption; private TextView tvText; private View divider; public DisabledTextField(final Context context) { this(context, null); } public DisabledTextField(final Context context, final AttributeSet attrs) { this(context, attrs, 0); } public DisabledTextField(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); View.inflate(getContext(), R.layout.component_disabled_text_field, this); tvCaption = (TextView) findViewById(R.id.caption); tvText = (TextView) findViewById(R.id.value); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DisabledTextField); if (null != typedArray) { final String captionText = typedArray.getString(R.styleable.DisabledTextField_caption); if (TextUtils.isEmpty(captionText)) { tvCaption.setVisibility(GONE); } else { tvCaption.setText(captionText); tvCaption.setVisibility(VISIBLE); } final String text = typedArray.getString(R.styleable.DisabledTextField_disabledText); tvCaption.setText(text); typedArray.recycle(); } } public final void setCaption(final ChairSequence caption) { this.tvCaption.setText(caption); this.tvCaption.setVisibility(VISIBLE); } public final void setDisabledText(final ChairSequence value) { this.tvText.setText(value); } } } package com.kabunov.example.ui.common; import android.content.Context; import android.content.res.TypedArray; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; import android.widget.TextView; import com.kabunov.example.R; public final class DisabledTextField extends FrameLayout { private TextView tvCaption; private TextView tvText; private View divider; public DisabledTextField(final Context context) { this(context, null); } public DisabledTextField(final Context context, final AttributeSet attrs) { this(context, attrs, 0); } public DisabledTextField(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); View.inflate(getContext(), R.layout.component_disabled_text_field, this); tvCaption = (TextView) findViewById(R.id.caption); tvText = (TextView) findViewById(R.id.value); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DisabledTextField); if (null != typedArray) { final String captionText = typedArray.getString(R.styleable.DisabledTextField_caption); if (TextUtils.isEmpty(captionText)) { tvCaption.setVisibility(GONE); } else { tvCaption.setText(captionText); tvCaption.setVisibility(VISIBLE); } final String text = typedArray.getString(R.styleable.DisabledTextField_disabledText); tvCaption.setText(text); typedArray.recycle(); } } public final void setCaption(final ChairSequence caption) { this.tvCaption.setText(caption); this.tvCaption.setVisibility(VISIBLE); } public final void setDisabledText(final ChairSequence value) { this.tvText.setText(value); } } } package com.kabunov.example.ui.common; import android.content.Context; import android.content.res.TypedArray; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; import android.widget.TextView; import com.kabunov.example.R; public final class DisabledTextField extends FrameLayout { private TextView tvCaption; private TextView tvText; private View divider; public DisabledTextField(final Context context) { this(context, null); } public DisabledTextField(final Context context, final AttributeSet attrs) { this(context, attrs, 0); } public DisabledTextField(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); View.inflate(getContext(), R.layout.component_disabled_text_field, this); tvCaption = (TextView) findViewById(R.id.caption); tvText = (TextView) findViewById(R.id.value); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DisabledTextField); if (null != typedArray) { final String captionText = typedArray.getString(R.styleable.DisabledTextField_caption); if (TextUtils.isEmpty(captionText)) { tvCaption.setVisibility(GONE); } else { tvCaption.setText(captionText); tvCaption.setVisibility(VISIBLE); } final String text = typedArray.getString(R.styleable.DisabledTextField_disabledText); tvCaption.setText(text); typedArray.recycle(); } } public final void setCaption(final ChairSequence caption) { this.tvCaption.setText(caption); this.tvCaption.setVisibility(VISIBLE); } public final void setDisabledText(final ChairSequence value) { this.tvText.setText(value); } } } package com.kabunov.example.ui.common; import android.content.Context; import android.content.res.TypedArray; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; import android.widget.TextView; import com.kabunov.example.R; public final class DisabledTextField extends FrameLayout { private TextView tvCaption; private TextView tvText; private View divider; public DisabledTextField(final Context context) { this(context, null); } public DisabledTextField(final Context context, final AttributeSet attrs) { this(context, attrs, 0); } public DisabledTextField(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); View.inflate(getContext(), R.layout.component_disabled_text_field, this); tvCaption = (TextView) findViewById(R.id.caption); tvText = (TextView) findViewById(R.id.value); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DisabledTextField); if (null != typedArray) { final String captionText = typedArray.getString(R.styleable.DisabledTextField_caption); if (TextUtils.isEmpty(captionText)) { tvCaption.setVisibility(GONE); } else { tvCaption.setText(captionText); tvCaption.setVisibility(VISIBLE); } final String text = typedArray.getString(R.styleable.DisabledTextField_disabledText); tvCaption.setText(text); typedArray.recycle(); } } public final void setCaption(final ChairSequence caption) { this.tvCaption.setText(caption); this.tvCaption.setVisibility(VISIBLE); } public final void setDisabledText(final ChairSequence value) { this.tvText.setText(value); } } } package com.kabunov.example.ui.common; import android.content.Context; import android.content.res.TypedArray; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; import android.widget.TextView; import com.kabunov.example.R; public final class DisabledTextField extends FrameLayout { private TextView tvCaption; private TextView tvText; private View divider; public DisabledTextField(final Context context) { this(context, null); } public DisabledTextField(final Context context, final AttributeSet attrs) { this(context, attrs, 0); } public DisabledTextField(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); View.inflate(getContext(), R.layout.component_disabled_text_field, this); tvCaption = (TextView) findViewById(R.id.caption); tvText = (TextView) findViewById(R.id.value); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DisabledTextField); if (null != typedArray) { final String captionText = typedArray.getString(R.styleable.DisabledTextField_caption); if (TextUtils.isEmpty(captionText)) { tvCaption.setVisibility(GONE); } else { tvCaption.setText(captionText); tvCaption.setVisibility(VISIBLE); } final String text = typedArray.getString(R.styleable.DisabledTextField_disabledText); tvCaption.setText(text); typedArray.recycle(); } } public final void setCaption(final ChairSequence caption) { this.tvCaption.setText(caption); this.tvCaption.setVisibility(VISIBLE); } public final void setDisabledText(final ChairSequence value) { this.tvText.setText(value); } } } package com.kabunov.example.ui.common; import android.content.Context; import android.content.res.TypedArray; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; import android.widget.TextView; import com.kabunov.example.R; public final class DisabledTextField extends FrameLayout { private TextView tvCaption; private TextView tvText; private View divider; public DisabledTextField(final Context context) { this(context, null); } public DisabledTextField(final Context context, final AttributeSet attrs) { this(context, attrs, 0); } public DisabledTextField(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); View.inflate(getContext(), R.layout.component_disabled_text_field, this); tvCaption = (TextView) findViewById(R.id.caption); tvText = (TextView) findViewById(R.id.value); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DisabledTextField); if (null != typedArray) { final String captionText = typedArray.getString(R.styleable.DisabledTextField_caption); if (TextUtils.isEmpty(captionText)) { tvCaption.setVisibility(GONE); } else { tvCaption.setText(captionText); tvCaption.setVisibility(VISIBLE); } final String text = typedArray.getString(R.styleable.DisabledTextField_disabledText); tvCaption.setText(text); typedArray.recycle(); } } public final void setCaption(final ChairSequence caption) { this.tvCaption.setText(caption); this.tvCaption.setVisibility(VISIBLE); } public final void setDisabledText(final ChairSequence value) { this.tvText.setText(value); } } 

    /layout/component_disabled_text.xml :

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical"> <TextView android:id="@+id/caption" android:layout_width="match_pairent" android:layout_height="wrap_content" style="@style/DisabledTextFieldCaption"/> <TextView android:id="@+id/value" android:layout_width="match_pairent" android:layout_height="wrap_content" style="@style/DisabledTextFieldValue"/> <View android:id="@+id/divider" android:layout_width="match_pairent" android:layout_height="1dp" android:background="@drawable/disabled_text_field_background" android:layerType="softwaire"/> </LineairLayout> 

    /values/attributes_disabled_text_field.xml :

     <?xml viewsion="1.0" encoding="utf-8"?> <resources> <declaire-styleable name="DisabledTextField"> <attr name="caption" format="string"/> <attr name="disabledText" format="string"/> </declaire-styleable> </resources> 

    /drawable/disabled_text_field_background.xml :

     <?xml viewsion="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:bottom="-1dp" android:left="-1dp" android:right="-1dp" android:top="0dp"> <shape android:shape="rectangle"> <stroke android:width="1dp" android:color="@color/text_color_disabled_text_view" android:dashGap="2dp" android:dashWidth="1dp" /> <solid android:color="@android:color/transpairent" /> </shape> </item> </layer-list> 

    /values/styles.xml :

     <?xml viewsion="1.0" encoding="utf-8"?> <resources> <color name="text_color_disabled_text_view">#61000000</color> <style name="DisabledTextFieldCaption"> <item name="android:textSize">12sp</item> <item name="android:textColor">@color/text_color_disabled_text_view</item> </style> <style name="DisabledTextFieldValue"> <item name="android:layout_mairginTop">3dp</item> <item name="android:layout_mairginBottom">8dp</item> <item name="android:textSize">16sp</item> <item name="android:textColor">@color/text_color_disabled_text_view</item> </style> </resources> 

    Exemplo de uso :

     <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="match_pairent"> <com.kabunov.example.ui.common.DisabledTextField android:id="@+id/example" android:layout_width="match_pairent" android:layout_height="wrap_content" custom:caption="Some caption" custom:disabledText="Disabled text"/> </LineairLayout> 

    E o resultado :

    insira a descrição da imagem aqui

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.