Skip to content

Instantly share code, notes, and snippets.

@wakwak3125
Last active January 11, 2016 15:59
Show Gist options
  • Save wakwak3125/4c7124f92e09aed07ca5 to your computer and use it in GitHub Desktop.
Save wakwak3125/4c7124f92e09aed07ca5 to your computer and use it in GitHub Desktop.
SnackBarの文字色を自由に設定する方法 ref: http://qiita.com/wakwak3125/items/79e0097767be5b2ea798
public class MainActivity extends AppCompatActivity {
@Bind(R.id.root)
LinearLayout root;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
private void showSnackBar(String msg, int color) {
Snackbar snackbar = Snackbar.make(root, msg, Snackbar.LENGTH_SHORT);
TextView textView = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(color);
snackbar.show();
}
@OnClick(R.id.red)
public void showRedTextSnackBar() {
showSnackBar("赤です", Color.RED);
}
@OnClick(R.id.blue)
public void showBlueTextSnackBar() {
showSnackBar("青です", Color.BLUE);
}
@OnClick(R.id.white)
public void showWhiteTextSnackBar() {
showSnackBar("白です", Color.WHITE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment