我有一个简单的应用程序,它有两个按钮,可以触发通知。在编程的后期,由于设计更好,我想把普通的底部改为图像底部,所以我删除了普通的底部,但图像底部在中,将id改回了原来的底部1和底部2,<strong],但现在它不再工作了>。我做错了什么?我必须编程不同于正常的图像底部吗?我必须安装libarys还是其他什么?请帮帮我!
xml:
<ImageButton
android:id="@+id/buttom2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/buttom1"
android:layout_below="@+id/buttom1"
android:layout_marginTop="23dp"
android:src="@drawable/icon2" />
<ImageButton
android:id="@+id/buttom1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="14dp"
android:src="@drawable/icon1" />
main.java:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void sendNotification(View view) {
switch(view.getId()){
case R.id.buttom1:
Notification1();
break;
case R.id.buttom2:
Notification2();
break;
}
}
private void Notification1() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setAutoCancel(true);
builder.setContentTitle("BasicNotification");
builder.setContentText("Test");
builder.setSmallIcon(R.drawable.icon1);
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
manager.notify((int) System.currentTimeMillis(), notification);
}
private void Notification2() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setAutoCancel(true);
builder.setContentTitle("BasicNotification");
builder.setContentText("Test");
builder.setSmallIcon(R.drawable.icon2);
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
manager.notify((int) System.currentTimeMillis(), notification);
}
}
谢谢你!
将此行添加到ImageButtons
android:onClick="sendNotification"
您更改了吗
Button yourButton = (ImageButton) findViewById(R.id.btn);
至
ImageButton yourButton = (ImageButton) findViewById(R.id.btn);
此外,如果您向我们展示一些代码,我们将能够在您的查询中为您提供更多帮助。