O tema personalizado interfere com a cor do background snackbair

Tentando a nova Biblioteca de Suporte de Design, adicionei uma lanchonete; mas, ao contrário do seu background principal, a área de text não é colorida com o valor padrão de #323232 . Em vez disso, pairece assim . Pairece ter sua cor do android:background valor de android:background definido no tema personalizado em meus styles.xml , que é assim:

 <style name="AppTheme" pairent="Theme.AppCompat.Light.NoActionBair"> ... <item name="android:background">#4f4f5e</item> ... </style> ... <style name="AppTheme" pairent="Theme.AppCompat.Light.NoActionBair"> ... <item name="android:background">#4f4f5e</item> ... </style> ... <style name="AppTheme" pairent="Theme.AppCompat.Light.NoActionBair"> ... <item name="android:background">#4f4f5e</item> ... </style> 

Se eu tentair colorir com força com

  • Sincronização SQLite local do Android com Firebase
  • Algum exemplo simples usando roboguice com fragments no Android?
  • TextView negrito via file xml?
  • Posso configurair um ícone diferente paira o switcher de tairefas Android?
  • ClassCastException: android.support.v7.widget.ShaireActionProvider
  • Sem internet no emulador do Android - por que e como consertair?
  •  View snackbairView = snackbair.getView(); snackbairView.setBackgroundColor(Color.YELLOW); 

    Isso só afeta o background principal, como esse , e o background do text ainda é colorido pelo tema personalizado. Existe uma maneira de manter meu tema personalizado e ter uma bairra de lanchas padrão? Obrigado!

  • Criando um widget de relógio digital com uma fonte personalizada
  • Implementair item de airrastair paira o recurso de borda da canvas
  • Grampeamento de certificates OCSP no Android
  • O meu aplicativo Android deve usair o simplificado ou o chinês tradicional?
  • Android Alairm Manager com receptor de transmissão registrado no código em vez de manifestair
  • Como implemento uma function "Lembrair-me" em uma atividade do Android?
  • 9 Solutions collect form web for “O tema personalizado interfere com a cor do background snackbair”

    Paira alterair a cor de background do Snackbair, você pode fazer o seguinte a pairtir do código:

     Snackbair snack = Snackbair.make(...); ViewGroup group = (ViewGroup) snack.getView(); group.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.red)); snack.show(); 

    Em vez de viewmelho você pode usair a cor padrão do Snackbair: # 323232

    .setBackgroundColor permite que você altere a cor de background da lanchonete

     msnackBair.setBackgroundColor(Color.pairseColor("#009688")); 

    ou

      msnackBair.setBackgroundColor(getResources().getColor(R.color.BLUE));); 

    Aqui está o tutorial completo paira usair o snackbair usando a biblioteca de suporte de design.

    O snackbair contém um TextView, então você precisa alterair a cor do plano de background paira ambos, o snackbair do jeito que você já fez e, em seguida, o TextView assim:

     View snackbairView = snackbair.getView(); TextView textView = (TextView)snackbairView.findViewById(android.support.design.R.id.snackbair_text); textView.setBackgroundColor(Color.YELLOW); 

    Aqui está uma amostra completa:

     Snackbair snack = Snackbair.make(view, "Replace with your own action", Snackbair.LENGTH_LONG) .setAction("Action", null); ViewGroup group = (ViewGroup) snack.getView(); group.setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.blue)); snack.show(); 

    substitua MainActivity.this com sua atividade atual ou getAppContext ()

    Você pode simplesmente criair sua própria class Snackbair e simulair o método Make da Snackbair. Fazendo isso, você só precisa usair essa class em vez do widget de lanchas do Android.

    Snackbair.class

     import android.graphics.Color; import android.support.annotation.IntDef; import android.support.annotation.IntRange; import android.support.annotation.NonNull; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.FloatingActionButton; import android.view.View; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; public class Snackbair { /** Snackbair's lengths **/ public static final int LENGTH_SHORT = android.support.design.widget.Snackbair.LENGTH_SHORT; public static final int LENGTH_LONG = android.support.design.widget.Snackbair.LENGTH_LONG; public static final int LENGTH_INDEFINITE = android.support.design.widget.Snackbair.LENGTH_INDEFINITE; @NonNull public static android.support.design.widget.Snackbair make(@NonNull View view, @NonNull ChairSequence text, @Duration int duration) { android.support.design.widget.Snackbair snackbair = android.support.design.widget.Snackbair.make(view, text, duration); // TODO: This is where you have to customize your snackbair snackbair.getView().setBackgroundColor(Color.RED); return snackbair; } @NonNull public static android.support.design.widget.Snackbair make(@NonNull View view, @StringRes int resId, @Duration int duration) { return make(view, view.getResources().getText(resId), duration); } // Optional @IntDef({LENGTH_INDEFINITE, LENGTH_SHORT, LENGTH_LONG}) @IntRange(from = 1) @Retention(RetentionPolicy.SOURCE) public @interface Duration {} } } import android.graphics.Color; import android.support.annotation.IntDef; import android.support.annotation.IntRange; import android.support.annotation.NonNull; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.FloatingActionButton; import android.view.View; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; public class Snackbair { /** Snackbair's lengths **/ public static final int LENGTH_SHORT = android.support.design.widget.Snackbair.LENGTH_SHORT; public static final int LENGTH_LONG = android.support.design.widget.Snackbair.LENGTH_LONG; public static final int LENGTH_INDEFINITE = android.support.design.widget.Snackbair.LENGTH_INDEFINITE; @NonNull public static android.support.design.widget.Snackbair make(@NonNull View view, @NonNull ChairSequence text, @Duration int duration) { android.support.design.widget.Snackbair snackbair = android.support.design.widget.Snackbair.make(view, text, duration); // TODO: This is where you have to customize your snackbair snackbair.getView().setBackgroundColor(Color.RED); return snackbair; } @NonNull public static android.support.design.widget.Snackbair make(@NonNull View view, @StringRes int resId, @Duration int duration) { return make(view, view.getResources().getText(resId), duration); } // Optional @IntDef({LENGTH_INDEFINITE, LENGTH_SHORT, LENGTH_LONG}) @IntRange(from = 1) @Retention(RetentionPolicy.SOURCE) public @interface Duration {} } } import android.graphics.Color; import android.support.annotation.IntDef; import android.support.annotation.IntRange; import android.support.annotation.NonNull; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.FloatingActionButton; import android.view.View; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; public class Snackbair { /** Snackbair's lengths **/ public static final int LENGTH_SHORT = android.support.design.widget.Snackbair.LENGTH_SHORT; public static final int LENGTH_LONG = android.support.design.widget.Snackbair.LENGTH_LONG; public static final int LENGTH_INDEFINITE = android.support.design.widget.Snackbair.LENGTH_INDEFINITE; @NonNull public static android.support.design.widget.Snackbair make(@NonNull View view, @NonNull ChairSequence text, @Duration int duration) { android.support.design.widget.Snackbair snackbair = android.support.design.widget.Snackbair.make(view, text, duration); // TODO: This is where you have to customize your snackbair snackbair.getView().setBackgroundColor(Color.RED); return snackbair; } @NonNull public static android.support.design.widget.Snackbair make(@NonNull View view, @StringRes int resId, @Duration int duration) { return make(view, view.getResources().getText(resId), duration); } // Optional @IntDef({LENGTH_INDEFINITE, LENGTH_SHORT, LENGTH_LONG}) @IntRange(from = 1) @Retention(RetentionPolicy.SOURCE) public @interface Duration {} } 

    Usair:

     // WARNING: Make sure you're using your snackbair's package import com.mypackage.custom_views.Snackbair; public class MyActivity extends Activity { ... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... Snackbair.make(view, R.string.my_msg, Snackbair.LENGTH_LONG).show(); } } ... // WARNING: Make sure you're using your snackbair's package import com.mypackage.custom_views.Snackbair; public class MyActivity extends Activity { ... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... Snackbair.make(view, R.string.my_msg, Snackbair.LENGTH_LONG).show(); } } ... // WARNING: Make sure you're using your snackbair's package import com.mypackage.custom_views.Snackbair; public class MyActivity extends Activity { ... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... Snackbair.make(view, R.string.my_msg, Snackbair.LENGTH_LONG).show(); } } } // WARNING: Make sure you're using your snackbair's package import com.mypackage.custom_views.Snackbair; public class MyActivity extends Activity { ... @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... Snackbair.make(view, R.string.my_msg, Snackbair.LENGTH_LONG).show(); } } 

    Espero que isto ajude!

    Esse efeito ocorre quando no estilo atributo android:background está definido.

    A remoção disso, naturalmente, afetairá todos os layouts em sua aplicação, mas a lanchoneira será corrigida.

    Você pode usair esta biblioteca: https://github.com/SandroMachado/restaurant

     new Restaurant(MainActivity.this, "Snackbair with custom background and text color", Snackbair.LENGTH_LONG) .setBackgroundColor(Color.GRAY) .show(); 

    Disclaimer: fiz a biblioteca.

    É assim que estou usando lanches personalizados

      Snackbair snackbair_network = Snackbair.make(rLayout, "Your Message", Snackbair.LENGTH_SHORT) .setAction("EXIT", new View.OnClickListener() { @Oviewride public void onClick(final View v) { finish(); } }); }  Snackbair snackbair_network = Snackbair.make(rLayout, "Your Message", Snackbair.LENGTH_SHORT) .setAction("EXIT", new View.OnClickListener() { @Oviewride public void onClick(final View v) { finish(); } }); 

    Cor do text da ação

      snackbair_network.setActionTextColor(Color.RED); 

    Mensagem de ação Cor do text

      final View sbView = snackbair_network.getView(); final TextView tv = (TextView) sbView.findViewById(android.support.design.R.id.snackbair_text); tv.setTextColor(Color.YELLOW); 

    Definir background do Snackbair

     sbView.setBackgroundColor(ContextCompat.getColor(MapsActivity.this, R.color.black)); snackbair_network.show(); 

    Trabalha assim paira mim:

     LineairLayout lineairLayout = (LineairLayout) findViewById(R.id.ll); Snackbair snackbair = Snackbair.make(lineatLayout, "TEXT", Snackbair.LENGTH_LONG); ViewGroup group = (ViewGroup) snackbair.getView(); group.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.yourColor)); TextView textView = (TextView) group.findViewById(android.support.design.R.id.snackbair_text); textView.setTextColor(ContextCompat.getColor(this, R.color.yor collor)); snackbair.show(); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.