获取警告:在布局文件中找到意外文本:“”
同样点击按钮,应用程序崩溃了。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/container">
<Button android:id="@+id/bntStartService"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/broadcast_intent"
android:onClick="broadcast_intent">
</Button>
</LinearLayout>
请帮忙。
答案 0 :(得分:0)
// try this way hope this will help you...
1. activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:id="@+id/container">
<Button android:id="@+id/bntStartService"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/broadcast_intent"
android:onClick="broadcast_intent">
</Button>
</LinearLayout>
2.MainActivity .java
public class MainActivity extends Activity{
private Button bntStartService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bntStartService = (Button) findViewById(R.id.bntStartService);
bntStartService.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
broadcast_intent(view);
}
});
}
private void broadcast_intent(View view){
Toast.makeText(this,"Button Clicked",Toast.LENGTH_SHORT).show();
}
}