Ich versuche, eine ImageButton
auf der rechten Seite der Titelleiste der Aktivität in Android hinzuzufügen, aber wenn ich Anwendung ausführen, gibt es Fehler Unfortunately app stopped
. helfen Sie bitte:wie ImageButton in der Titelleiste hinzufügen
custom_title.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.abc.myapplication.MainActivity">
<ImageButton
android:id="@+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:focusable="true"
android:focusableInTouchMode="false"
android:src="@android:drawable/star_big_on"
android:background="@null" />
</RelativeLayout>
MainActivity.java
package com.example.abc.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
}
}
Was sehen Sie im Protokoll? –
Verwenden Sie LogCat, um die Java-Stack-Ablaufverfolgung zu untersuchen, die mit Ihrem Absturz verknüpft ist: https://stackoverflow.com/questions/23353173/unidy-myapp-has-stopped-how-can-i-solve-this – CommonsWare
Die Schaltfläche wird nicht in angezeigt Titelleiste. kein Fehler bei allen –