7
votes

Comment définir le style de conception de matériau pour désactiver EditText (Android)?

J'essaie de rendre mon style handicapé Editext comme dans les directives:

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

J'ai déjà implémenté des styles de conception de matériaux, tous mes widgets ont l'air matériel .

La question est la suivante: y a-t-il un moyen d'obtenir ce soulignement en pointillé à l'aide de styles , sans mettre des vues supplémentaires?

Mon styles.xml : xxx


3 Réponses :


0
votes

afaik, il n'y a pas de "stock". Prenez les directives de conception des matériaux tel qu'il est, une ligne directrice;)


0 commentaires

0
votes

Enfin, j'ai fini par une vue personnalisée. Ce n'est peut-être pas la solution la plus élégante, mais cela résout ma tâche.

J'espère que ce sera utile pour quelqu'un. P>


DisabledTextfield.java P>: P>: P> xxx pré>

/layout/component_disabled_text.xml strong>: p> xxx pré>

/values/attributes_disabled_text_field.xml :

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


        <com.kabunov.example.ui.common.DisabledTextField
            android:id="@+id/example"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            custom:caption="Some caption"
            custom:disabledText="Disabled text"/>

</LinearLayout>

/drawable/disabled_text_field_background.xml:

<?xml version="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_marginTop">3dp</item>
        <item name="android:layout_marginBottom">8dp</item>
        <item name="android:textSize">16sp</item>
        <item name="android:textColor">@color/text_color_disabled_text_view</item>

    </style>

</resources>

/values/styles.xml strud>: p> xxx pré>

Exemple d'utilisation forte>: p>

<?xml version="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/transparent" />

        </shape>
    </item>
</layer-list>


0 commentaires

1
votes

Enfin, j'ai réussi à faire comme vous l'avez montré, on dirait Échantillon

Créer en pointillé.xml code> Intérieur Dossier CODE> Dossier et coller ces P>

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


0 commentaires