2016-08-30 14 views
6

enter image description hereZmień kolor selektora hasłem Maska

Jak widać na zdjęciu mam android aplikacji z czarnym tłem i białym tekstem. Jednak nie istnieje w rzeczywistości „Pokaż tekst” ikona, która wygląda jak „oko” i to jest czarne jak dobrze :(. Czy sposób zmienić kolor tego?

activity_login.xml

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fitsSystemWindows="true" 
    android:background="@color/black"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="56dp" 
     android:paddingLeft="24dp" 
     android:paddingRight="24dp"> 

     <ImageView android:src="@drawable/logo" 
      android:layout_width="wrap_content" 
      android:layout_height="72dp" 
      android:layout_marginBottom="24dp" 
      android:layout_gravity="center_horizontal" /> 

     <!-- Email Label --> 
     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="8dp" 
      android:layout_marginBottom="8dp" 
      android:textColorHint="#ffffff"> 
      <EditText android:id="@+id/input_email" 
       android:theme="@style/MyEditTextTheme" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="textEmailAddress" 
       android:hint="E-Mail Address"/> 
     </android.support.design.widget.TextInputLayout> 

     <!-- Password Label --> 
     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="8dp" 
      android:layout_marginBottom="8dp" 
      android:textColor="#ffffff" 
      android:textColorHint="#ffffff"> 
      <EditText android:id="@+id/input_password" 
       android:theme="@style/MyEditTextTheme" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="textPassword" 
       android:hint="Password"/> 
     </android.support.design.widget.TextInputLayout> 

     <android.support.v7.widget.AppCompatButton 
      android:id="@+id/btn_login" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="24dp" 
      android:layout_marginBottom="24dp" 
      android:padding="12dp" 
      android:text="Login"/> 

     <TextView android:id="@+id/link_signup" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="24dp" 
      android:text="No account yet? Create one" 
      android:textColor="#ffffff" 
      android:gravity="center" 
      android:textSize="16dip"/> 

    </LinearLayout> 
</ScrollView> 

strings.xml

<resources> 
    <color name="bg_color">#ffffff</color> 
    <color name="black">#222222</color> 
    <style name="MyEditTextTheme"> 
     <item name="colorControlNormal">#ffffff</item> 
     <item name="colorControlActivated">#ffffff</item> 
     <item name="colorControlHighlight">#ffffff</item> 
     <item name="colorAccent">@android:color/white</item> 
     <item name="android:textColor">#ffffff</item> 
     <item name="android:textColorHint">#ffffff</item> 
    </style> 
</resources> 

Odpowiedz

0

Dodaj odkształcalne plik selector.xml:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" android:drawable="@color/dim_orange_btn_pressed" /> 
    <item android:state_focused="true" android:drawable="@color/dim_orange_btn_pressed" /> 
    <item android:drawable="@android:color/white" /> 
</selector> 

dodać EditText Thi s linia android:background="@drawable/selector"

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
      <EditText android:id="@+id/txt_pass" 
      android:theme="@style/MyEditTextTheme" 
      android:layout_width="match_parent" 
      android:background="@drawable/selector" 
      android:layout_height="wrap_content" 
      android:inputType="textPassword" 
      android:hint="E-Mail Address"/> 

     <ImageButton 
     android:id="@+id/btn_eye" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/eye" 
     /> 
    </LinearLayout> 

W kodzie:

buttonEye.setOnTouchListener(new OnTouchListener() { 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     if(event.getAction() == MotionEvent.ACTION_DOWN) { 

      txt_pass.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); 

     } else if (event.getAction() == MotionEvent.ACTION_UP) { 

      txt_pass.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); 
     } 
    } 
}; 
+0

Wow, dziękuję za przydatną edycję i szybką odpowiedź! :), próbowałem tej edycji, ale powiedziałem, że potrzebuję nazwy dla każdego przedmiotu, czy ma znaczenie, jakie są nazwy elementów? Wszystkich noob tutaj przepraszam. Jeśli byłbyś tak uprzejmy, aby wyjaśnić więcej. – rapid3642

+0

Dziękuję za bycie bardziej przejrzystym z twoją edycją, jednak zrobiłem to, ale to sprawia, że ​​całe pole jest białe, celem, którego próbuję osiągnąć, jest sprawienie, by wskaźnik "oko" lub "maska ​​maski" był biały. Czy jest jakiś sposób na zrobienie tego? Przepraszam, jeśli wcześniej nie byłam jasna. – rapid3642

+0

Mogę wyzywająco być w błędzie, ale nie sądzę, że dodanie słuchacza i ustawienie go do pokazania lub ukrycia spowoduje zmianę koloru, którą próbuję osiągnąć, jestem noobem, więc może jestem zły tutaj, ale jeśli tak, proszę wyjaśnij, żebym mógł zrozumieć więcej :) – rapid3642

4

rapid3642 „s odpowiedź wskazał w dobrym kierunku, ale nadal potrzebne, aby dowiedzieć się, co dokładnie będzie działać.

następujące kroki, aby zmienić kolor swojego kolanowej rozciągliwej:

  1. Tworzenie selector_password_visibility_toggle w ~/res/color/:

    <?xml version="1.0" encoding="utf-8"?> 
    <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
        <!-- When password is shown as text, the drawable will be off_white coloured --> 
        <item android:color="@color/off_white" android:state_checked="true"/> 
        <item android:color="@android:color/white"/> 
    
    </selector> 
    
  2. Dodaj passwordToggleTintMode i passwordToggleTint do TextInputLayout, jak poniżej:

    <android.support.design.widget.TextInputLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        app:passwordToggleTintMode="src_atop" 
        app:passwordToggleTint="@color/selector_password_visibility_toggle" 
        app:passwordToggleEnabled="true"> 
    

Teraz twój TextInputLayout będzie miał zmieniony kolor do rysowania.

+0

Dziękujemy za dodanie tego, co sprawdziło się dla Ciebie! Mam nadzieję, że to pomoże innym! :) – rapid3642

0

Jeśli używasz tła dla edittext lub texteditlayout, przełącznik widoczności hasła jest ukryty pod tłem. Więc usuń tło lub utwórz własny styl i uczyń go jako motyw dla edittext w układzie xml.

<style name="EditText_theme" parent=""> 
     <item name="passwordToggleTintMode">src_over</item> 
    </style> 

Jeśli nadal masz do czynienia z problemem lub nie masz żadnego tła, zmień motyw samej aplikacji, ponieważ tam określone są główne kolory.

Oto inne obejście, które nie zadziałało. Dostałem go z samego google docs,

<style name="EditText_theme" parent=""> 
     <item name="passwordToggleTint">@color/white</item> 
    </style> 
3

Dodaj następujący xmlns: app w swoim układzie.

xmlns:app="http://schemas.android.com/apk/res-auto"

Teraz ustaw passwordToggleEnabled&passwordToggleTint w EditText odpowiednio

app:passwordToggleEnabled = "true"
app:passwordToggleTint="#FFFFFF"

0

Tutaj jest dobrym sposobem, aby to zrobić programowo:

Wywołanie tej metody w obiekcie TextInputLayout.