简体   繁体   中英

Is there a way to use Twitter Digits without the button in Android?

我正在制作一个使用Twitter数字的应用程序,我想知道是否有办法使用它而不使用丑陋的Twitter数字按钮,上面写着“ 使用我的电话号码

You have to modify the button programmatically, using xml won't work. For example:

digitsButton.setText("Your text here");
digitsButton.setBackgroundColor(getResources().getColor(R.color.primary));

You can use your own button and just call Digits.authenticate()

final AuthCallback digitsCallback = new AuthCallback() {
    @Override
    public void success(DigitsSession session, String phoneNumber) {
        // Do something on success
    }

    @Override
    public void failure(DigitsException exception) {
        // Do something on failure
    }
};

findViewById(R.id.myButton).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Digits.authenticate(digitsCallback);
    }
});

Try this the OnClickListener of your custom button:

AuthConfig.Builder builder = new AuthConfig.Builder();

builder.withAuthCallBack(new AuthCallback() {
    @Override
    public void success(DigitsSession session, String phoneNumber) {
        Toast.makeText(getApplicationContext(), "Authentication successful for "
            + phoneNumber, Toast.LENGTH_LONG).show();

            // Do something
         }

     @Override
     public void failure(DigitsException error) {
         // Do something
     }
});

AuthConfig authConfig = builder.build();

Digits.authenticate(authConfig);

By now you even got an answer. But just in case, most easy way to customize the DigitsAuth Button would be following below:

  1. Create a new background image and name it as dgts__digits_btn.png ==> this would replace the bg image of digiAuth button.
  2. Change padding around the DigitsAuthButton button by adding tw__login_btn_drawable_padding attribute in dimens.xml
  3. Change default DigitsAuthButton button text by adding string entry with name "dgts__login_digits_text" in strings.xml
  4. Change text size by adding "tw__login_btn_text_size" in dimens.xml
  5. DigitsAuthButton Button padding by adding "tw__login_btn_right_padding" and dimens.xml

Hope this helps.

using Android Data Binding library

XML file

<layout xmlns:android="http://schemas.android.com/apk/res/android" >

    <data>

        <variable
            name="viewModel"
            type="package.DigitsViewModel" />
    </data>

    ...
    <com.digits.sdk.android.DigitsAuthButton
        ...
        android:text="@{viewModel.mDigitsButtonText}"
        android:background="@{viewModel.mDigitsButtonDrawable}" />

</layout>

DigitsViewModel file

public final ObservableField<String> mDigitsButtonText = new ObservableField<>();
public final ObservableField<Drawable> mDigitsButtonDrawable = new ObservableField<>();

mDigitsButtonText.set("Your text here");
mDigitsButtonDrawable.set(ContextCompat.getDrawable(mContext, R.drawable.some_drawable));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM