我想在标题栏中添加一个Button。我已经按照本教程。 How to add Button因此我有以下课程:
public class CustomWindow extends Activity {
protected TextView title;
protected ImageView icon;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Request for custom title bar
this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
//set to your layout file
setContentView(R.layout.activity_amtob);
//Set the titlebar layout
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
}
public void linkedinBtnClicked(View v)
{
//Implement the button click event
//Toast.makeText(this, "Button is clicked", Toast.LENGTH_LONG).show();
}
}
在title.xml中,我有以下代码:
<RelativeLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="40dp"
android:orientation="horizontal" android:paddingLeft="5dp"
>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subscriber Verification"
/>
<ImageButton android:src="@drawable/logout"
android:layout_width="28dp"
android:layout_height="28dp" android:clickable="true"
android:layout_alignParentRight="true"
android:id="@+id/linkedinBtn"
android:onClick="linkedinBtnClicked" />
</RelativeLayout>
但是当我按如下方式扩展CustomWindow时,我得到了异常并且活动关闭了。
public class AMTOB_activity extends CustomWindow implements View.OnClickListener {
String fingerPrintDataFileName = null;
Button grabFingerData, sendRequest, photoUploader;
public String photoBytes = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_amtob);
grabFingerData = (Button) findViewById(R.id.grabDataButtonId);
grabFingerData.setOnClickListener(this);
sendRequest = (Button) findViewById(R.id.sendReq);
sendRequest.setOnClickListener(this);
// sendRequest.setVisibility(View.GONE);
}
}
为什么会发生此异常?我怎样才能解决这个异常?如何查看发生了什么异常?