下面列出了android.widget.Button#getText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void showToast(Button btn) {
if (toast != null) {
toast.cancel();
}
String text = "Clicked: " + btn.getText();
toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
toast.show();
}
private void showToast(Button btn) {
if (toast != null) {
toast.cancel();
}
String text = "Clicked: " + btn.getText();
toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
toast.show();
}
private void showToast(Button btn) {
if (toast != null) {
toast.cancel();
}
String text = "Clicked: " + btn.getText();
toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
toast.show();
}
private void showToast(Button btn) {
if (toast != null) {
toast.cancel();
}
String text = "Clicked: " + btn.getText();
toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
toast.show();
}
/**
* Checks if a button is existed in the screen.
*
* @param buttonName the name string of the button
* @param isWait whether wait the text
* @param isClick whether click the button if find it
* @return the button to search, and null means can not find the button
*/
public static View getButtonOnScreen(String buttonName, boolean isWait, boolean isClick) {
View button = null;
instrumentation.waitForIdleSync();
if (isWait) {
SOLO.waitForText(buttonName);
}
// Find on action bar.
if (hasActionBar) {
ArrayList<View> allViews = SOLO.getViews();
for (View view : allViews) {
String className = view.getClass().getName();
if (className.indexOf("ActionMenuItemView") > 0) {
String menuItemNameString = view.getContentDescription().toString();
if (menuItemNameString.equalsIgnoreCase(buttonName)) {
button = view;
break;
}
}
}
}
// Get all buttons and find.
if (button == null) {
ArrayList<Button> currentButtons = SOLO.getCurrentViews(Button.class);
for (Button oneButton : currentButtons) {
String title = (String) oneButton.getText();
if (title.equalsIgnoreCase(buttonName)) {
button = oneButton;
}
}
}
if (button != null && isClick) {
SOLO.clickOnView(button);
}
if (button == null && isClick) {
Log.d(TAG, "Don't find the button " + buttonName);
}
return button;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnSimpleNotification = findViewById(R.id.btnSimpleNotification);
Button btnNotificationIcon = findViewById(R.id.btnNotificationIcon);
Button btnNotificationImage = findViewById(R.id.btnNotificationImage);
Button btnNotificationWithGroupConvo = findViewById(R.id.btnNotificationWithGroupConvo);
Button btnNotificationSemantic = findViewById(R.id.btnNotificationSemantic);
charSequence = btnNotificationIcon.getText();
btnSimpleNotification.setOnClickListener(this);
btnNotificationIcon.setOnClickListener(this);
btnNotificationImage.setOnClickListener(this);
btnNotificationWithGroupConvo.setOnClickListener(this);
btnNotificationSemantic.setOnClickListener(this);
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence name = "My Notification";
String description = "yadda yadda";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
channel = new NotificationChannel("1", name, importance);
channel.setDescription(description);
builder = new NotificationCompat.Builder(MainActivity.this, channel.getId())
.setSmallIcon(R.mipmap.ic_launcher);
notificationManager.createNotificationChannel(channel);
}