我正在制作一个使用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:
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.