是xml文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/notification_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="?android:windowBackground"
android:clickable="true"
tools:openDrawer="start">
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/notification_app_bar_main"
/>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:fitsSystemWindows="true"
android:id="@+id/notification_navigationView"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
app:itemIconTint="@color/App_Pink"
app:itemTextColor="@color/white"
android:background="@color/black"
app:theme="@style/NavigationTheme"
/>
</android.support.v4.widget.DrawerLayout>
是java类
public class FragmentNotice extends Fragment implements NavigationView.OnNavigationItemSelectedListener {
private ProgressDialog progressdialog;
private DrawerLayout drawer;
private RecyclerView notificationrecyclerview;
private ArrayList<NotificationListModel> arrayList=new ArrayList();
private ActionBarDrawerToggle toggle;
private View view1;
private CircularImageView navigationheader_image_profile;
TextView name;
TextView sign_in;
TextView view_profile;
LinearLayout upgrade_layout;
LinearLayout linearLayout4;
AppCompatActivity activity;
ImageView notice_drawer;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.notice, null);
Toolbar toolbar = (Toolbar)view.findViewById(R.id.toolbar);
activity = (AppCompatActivity)getActivity();
activity.setSupportActionBar(toolbar);
drawer = (DrawerLayout)view.findViewById(R.id.notification_drawer_layout);
NavigationView navigationView = (NavigationView)view.findViewById(R.id.notification_navigationView);
navigationView.setNavigationItemSelectedListener(this);
notificationrecyclerview=(RecyclerView)view.findViewById(R.id.notificationrecyclerview);
toggle = new ActionBarDrawerToggle(
getActivity(), drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.setDrawerIndicatorEnabled(false);
toggle.syncState();
view1= navigationView.getHeaderView(0);
navigationheader_image_profile=(CircularImageView)view1.findViewById(R.id.navigationheader_image_profile);
name=(TextView)view1.findViewById(R.id.name);
sign_in=(TextView)view1.findViewById(R.id.sign_in);
view_profile=(TextView)view1.findViewById(R.id.view_profile);
upgrade_layout=(LinearLayout)view1.findViewById(R.id.upgrade_layout);
linearLayout4=(LinearLayout)view1.findViewById(R.id.linearLayout4);
onNotificationExecute();
onFetchingUserName();
return view;
}
/* @Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
toggle.syncState();
}
*/
@Override
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
toggle.syncState();
}
private void onFetchingUserName() {
String user_id=String.valueOf(HelperEditProfile.read("user id",0));
String Url = HechatConstants.url+"/api/users/"+user_id;
GetServiceMethod fetchinguserdetail=new GetServiceMethod(userdetailresult,Url,"GET","");
fetchinguserdetail.execute();
}
Callback userdetailresult=new Callback() {
@Override
public void result(String jsonString) {
if(jsonString!=null) {
try {
JSONObject jsonobject=new JSONObject(jsonString);
JSONObject data=jsonobject.getJSONObject("data");
String url= data.getString("fileUrl");
name.setText(data.getString("userName"));
Picasso.with(getActivity()).load(url).into(navigationheader_image_profile);
} catch (JSONException e) {
e.printStackTrace();
}
}
else {
Toast.makeText(getActivity(),"could not fetch your details",Toast.LENGTH_LONG).show();
}
}
};
private void onNotificationExecute() {
String url= HechatConstants.url+"/api/notifications";
progressdialog=new ProgressDialog(getActivity());
progressdialog.setMessage("Fetching notification");
progressdialog.show();
GetApiWithHeader notificationlist=new GetApiWithHeader(notificationresult,url,"GET","");
notificationlist.execute();
}
Callback notificationresult=new Callback() {
@Override
public void result(String jsonString) {
if(progressdialog.isShowing()) {
progressdialog.dismiss();
}
if(jsonString!=null) {
try {
JSONObject jsonObject=new JSONObject(jsonString);
JSONArray jsonArray=jsonObject.getJSONArray("data");
if(jsonArray.length()>0){
SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
simpledateformat.setTimeZone(TimeZone.getTimeZone("GMT"));
for(int i=0;i<jsonArray.length();i++) {
int actiontype = 0;
boolean issent=false;
boolean isRead=false;
String useridname=null;
String oweneridname=null;
String owenerprofile=null;
String ago=null;
if(jsonArray.getJSONObject(i).has("actionType")) {
if(jsonArray.getJSONObject(i).getString("actionType").equals("null")){
}
else {
actiontype= jsonArray.getJSONObject(i).getInt("actionType");
}
}
if(jsonArray.getJSONObject(i).has("isSent")) {
issent= jsonArray.getJSONObject(i).getBoolean("isSent");
}
if(jsonArray.getJSONObject(i).has("isRead")) {
isRead= jsonArray.getJSONObject(i).getBoolean("isRead");
}
if(jsonArray.getJSONObject(i).getJSONObject("user").has("userName")) {
useridname= jsonArray.getJSONObject(i).getJSONObject("user").getString("userName");
}
if(jsonArray.getJSONObject(i).has("owner")) {
oweneridname = jsonArray.getJSONObject(i).getJSONObject("owner").getString("userName");
owenerprofile = jsonArray.getJSONObject(i).getJSONObject("owner").getString("fileUrl");
}
if(jsonArray.getJSONObject(i).has("created_at")) {
if(jsonArray.getJSONObject(i).getJSONObject("created_at").has("date")) {
String createdat= jsonArray.getJSONObject(i).getJSONObject("created_at").getString("date");
long time = simpledateformat.parse(createdat).getTime();
long now = System.currentTimeMillis();
CharSequence agotime = DateUtils.getRelativeTimeSpanString(time, now, DateUtils.MINUTE_IN_MILLIS);
ago= String.valueOf(agotime);
}
}
arrayList.add(new NotificationListModel(actiontype,issent,isRead,useridname,oweneridname,owenerprofile,ago));
}
}
NotificationListAdapter notificationlistadapter=new NotificationListAdapter(getActivity(),arrayList);
final LinearLayoutManager linearLayoutManager=new LinearLayoutManager(getActivity());
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
notificationrecyclerview.setLayoutManager(linearLayoutManager);
notificationrecyclerview.setHasFixedSize(true);
notificationrecyclerview.addItemDecoration(new DividerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL));
notificationrecyclerview.setAdapter(notificationlistadapter);
} catch (JSONException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
else {
Toast.makeText(getActivity(),"no notification",Toast.LENGTH_LONG).show();
}
}
};
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (toggle.onOptionsItemSelected(item)) {
return true;
}
//add your switch statement
return super.onOptionsItemSelected(item);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(toggle!=null) {
toggle.onConfigurationChanged(newConfig);
}
}
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.friends) {
Intent i=new Intent(getActivity(),Friends_Recyclerview.class);
startActivity(i);
} else if (id == R.id.follower) {
Intent i=new Intent(getActivity(),Followers_Recyclerview.class);
startActivity(i);
} else if (id == R.id.following) {
Intent i=new Intent(getActivity(),Following_Recyclerview.class);
startActivity(i);
} else if (id == R.id.match_me) {
Intent i=new Intent(getActivity(),Match_Me_Recyclerview.class);
startActivity(i);
} else if (id == R.id.invisible_mode) {
Intent i=new Intent(getActivity(),Invisible_Mode.class);
startActivity(i);
} else if (id == R.id.blocks) {
Intent i=new Intent(getActivity(),Manage_Blocks.class);
startActivity(i);
} else if (id == R.id.rate_us) {
} else if (id == R.id.faq) {
} else if (id == R.id.feedback) {
} else if (id == R.id.logout) {
Intent i=new Intent(getActivity(),Alert_dialog_box.class);
i.putExtra("get_data","logout_dialog");
startActivity(i);
} else if (id == R.id.privacy) {
Intent i=new Intent(getActivity(),Privacy_Settings.class);
startActivity(i);
}
drawer.closeDrawer(GravityCompat.END);
return true;
}
}
当我滑动时,抽屉打开和关闭,但是没有显示汉堡图标 when i swipe from right to left then drawer open
when page open then it looks like this
提前致谢
答案 0 :(得分:0)
删除此行
toggle.setDrawerIndicatorEnabled(false);
答案 1 :(得分:0)
您可以是用户
toggle.setDrawerIndicatorEnabled (true)
或
对于自定义指示器,您可以使用以下内容
toggle.setHomeAsUpIndicator(R.drawable.your_drawable_file)
;