Skip to content

Instantly share code, notes, and snippets.

@snadjafi
Last active August 29, 2015 14:22
Show Gist options
  • Save snadjafi/ed93687a4e1d4f0b0996 to your computer and use it in GitHub Desktop.
Save snadjafi/ed93687a4e1d4f0b0996 to your computer and use it in GitHub Desktop.
@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findViewById(R.id.first).setOnClickListener(this);

    LoadingButton button = new LoadingButton(this);
    LoadingButton.ViewSwitcherFactory factory = new LoadingButton.ViewSwitcherFactory(this,
            getResources().getColor(android.R.color.white),
            44F,
            Typeface.DEFAULT);
    button.setTextFactory(factory);

    button.setText("Press");
    button.setLoadingText("wait...");
    button.setBackgroundColor(Color.RED);
    button.setOnClickListener(this);
    button.setAnimationInDirection(LoadingButton.IN_FROM_LEFT);
    ((ViewGroup) findViewById(R.id.root)).addView(button);
}

@Override public void onClick(final View v) {
    ((LoadingButton) v).showLoading();

    v.postDelayed(new Runnable() {
        @Override public void run() {
            ((LoadingButton) v).showButtonText();
        }
    }, 2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment