0
Ich versuche, Symbolmenü in der Symbolleiste hinzuzufügen. aber mein Icon wird nicht angezeigt. hier mein Code. Nur leere Kopfzeile anzeigen. kann mir jemand helfen ...Warum mein Menüsymbol nicht in der Symbolleiste angezeigt wird, zeige nur leere Symbolleiste
dieses Fragment Klasse
package com.example.bams.task.fragments;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.example.bams.task.R;
/**
* Created by jack on 19/02/2017.
*/
public class AddProjectFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
Toolbar myToolbar = (Toolbar) getActivity().findViewById(R.id.my_toolbar);
((AppCompatActivity) getActivity()).setSupportActionBar(myToolbar);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_add_project, container,false);
return rootView;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
//menu.clear();
inflater.inflate(R.menu.header, menu);
super.onCreateOptionsMenu(menu, inflater);
}
}
dieses Layout meine benutzerdefinierte Symbolleiste
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/colorBgFragment"
android:fitsSystemWindows="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBgFragment">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Name"
android:ems="10"
android:id="@+id/editText"/>
</LinearLayout>
</LinearLayout>
und mein Menüsymbol jemand
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/backBtn"
android:icon="@drawable/ic_back_filled"
app:showAsAction="always"
android:title="back"/>
</menu>
kann sagen, ist mir
was falsch mit meinem Code?
Welche Thema sind Sie für Ihre Anwendung oder dieses Fragment Einstellung? füge auch einen Screenshot hinzu. –
Ich ändere