Hamburger menu is not correctly placed in android - java

Hi everyone i am working on hamburger menu in android application, where my problem is the hamburger menu is placed at wrong place(few steps down). I need the hamburger menu below my tool bar of window. please help me in this regard.
My java code:
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
// Creating Hamburger Menu
final TextView userName_ham = (TextView) this.findViewById(R.id.userName_hamburger);
ParseQuery<DriverDetails> query = new ParseQuery<DriverDetails>("driverDetails");
Log.d(TAG_NAME, "Driver Phone No" + driverPhoneNo);
query.whereEqualTo("PhoneNo", driverPhoneNo);
query.findInBackground(new FindCallback<DriverDetails>() {
#Override
public void done(List<DriverDetails> objects, ParseException e) {
if (e == null) {
if (objects.size() != 0) {
driverName = objects.get(0).getString("driverNameFirst");
Log.d(TAG_NAME, "DriverName inside" + driverName);
editor.putString("driverName", driverName);
editor.apply();
userName_ham.setText("Welcome " + driverName);
}
}
}
});
Log.d(TAG_NAME, "DriverName" + driverName);
mNavItems.add(new NavItem("Earnings", R.drawable.earnings));
mNavItems.add(new NavItem("History", R.drawable.history));
mNavItems.add(new NavItem("About", R.drawable.about));
mNavItems.add(new NavItem("Share", R.drawable.share));
mNavItems.add(new NavItem("Notification", R.drawable.notification));
mNavItems.add(new NavItem("Settings", R.drawable.settings));
mNavItems.add(new NavItem("Logout", R.drawable.logout));
// DrawerLayout
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
// Populate the Navigation Drawer with options
mDrawerPane = (RelativeLayout) findViewById(R.id.drawerPane);
mDrawerList = (ListView) findViewById(R.id.navList);
DrawerListAdapter drawerAdapter = new DrawerListAdapter(this, mNavItems);
mDrawerList.setAdapter(drawerAdapter);
mDrawerList.setFitsSystemWindows(true);
// Drawer Item click listeners
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItemFromDrawer(position);
}
});
My xml file code:
<!-- The navigation drawer -->
<RelativeLayout
android:layout_width="280dp"
android:layout_height="match_parent"
android:id="#+id/drawerPane"
android:fitsSystemWindows="true"
android:layout_gravity="start">
<!-- Profile Box -->
<RelativeLayout
android:id="#+id/profileBox"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#color/colorPrimary"
android:padding="8dp" >
<ImageView
android:id="#+id/avatar"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/user"
android:clickable="false"
android:layout_marginTop="15dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/avatar"
android:orientation="vertical" >
<TextView
android:id="#+id/userName_hamburger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome"
android:textColor="#fff"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/view_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="4dp"
android:text="View Profile"
android:clickable="true"
android:textColor="#fff"
android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>
<!-- List of Actions (pages) -->
<ListView
android:id="#+id/navList"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_below="#+id/profileBox"
android:choiceMode="singleChoice"
android:background="#ffffffff" />
</RelativeLayout>
My activity xml file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".ui.DriverScreenActivity">
<android.support.design.widget.AppBarLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:theme="#style/AppTheme.AppBarOverlay"/>
<include layout="#layout/content_customer_screen" />
<android.support.design.widget.FloatingActionButton android:id="#+id/logout"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="160sp"
android:scaleType="fitXY"
android:src="#drawable/btn_logout" />
</android.support.design.widget.CoordinatorLayout>

Related

How to set title and back arrow button in toolbar for each fragment?

//Here is my fragment
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white">
<RelativeLayout
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="#dimen/_420sdp"
android:background="#EAEAEA"
>
<RelativeLayout
android:id="#+id/home_bg_layout"
android:layout_width="match_parent"
android:layout_height="#dimen/_400sdp"
android:background="#drawable/sama">
<Button
android:id="#+id/bookAppointmentBtn"
android:layout_width="match_parent"
android:layout_height="#dimen/_55sdp"
android:layout_marginLeft="#dimen/_30sdp"
android:layout_marginRight="#dimen/_30sdp"
android:fontFamily="#string/roboto_light"
android:textSize="#dimen/_20sdp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="#dimen/_10sdp"
android:background="#drawable/book_appointmentbg"
android:textColor="#color/white"
android:text="#string/bookappointment" />
</RelativeLayout>
</RelativeLayout>
<Button
android:id="#+id/ContactNoBtn"
android:layout_width="match_parent"
android:layout_height="#dimen/_46sdp"
android:text="#string/shop_number"
android:textColor="#ffffff"
android:textSize="#dimen/_25sdp"
android:layout_below="#+id/discountsTv"
android:textAllCaps="false"
android:layout_marginRight="#dimen/_30sdp"
android:layout_marginTop="#dimen/_5sdp"
android:layout_marginLeft="#dimen/_30sdp"
android:background="#drawable/black_background"/>
<LinearLayout
android:id="#+id/servicesLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:layout_marginLeft="#dimen/_20sdp"
android:layout_marginRight="#dimen/_20sdp"
android:orientation="horizontal"
android:layout_below="#+id/servicesupperview"
>
<LinearLayout
android:id="#+id/menLayout"
android:layout_width="#dimen/_108sdp"
android:layout_height="#dimen/_27sdp"
android:layout_margin="#dimen/_10sdp"
android:layout_weight="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#string/roboto_medium"
android:textColor="#535353"
android:layout_marginStart="#dimen/_17sdp"
android:layout_marginTop="#dimen/_5sdp"
android:textSize="#dimen/_12sdp"
android:text="#string/mens"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/womenLayout"
android:layout_width="#dimen/_108sdp"
android:layout_height="#dimen/_27sdp"
android:layout_margin="#dimen/_10sdp"
android:layout_weight="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#string/roboto_medium"
android:textSize="#dimen/_12sdp"
android:layout_marginStart="#dimen/_10sdp"
android:layout_marginTop="#dimen/_5sdp"
android:textColor="#535353"
android:text="#string/womens"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/childrenLayout"
android:layout_width="#dimen/_108sdp"
android:layout_height="#dimen/_27sdp"
android:layout_margin="#dimen/_10sdp"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/_12sdp"
android:fontFamily="#string/roboto_medium"
android:textColor="#535353"
android:layout_marginStart="#dimen/_20sdp"
android:layout_marginTop="#dimen/_5sdp"
android:text="#string/children_caps"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I am having toolbar in MainActivity. This is my fragment i want to set title, image and back button inside the toolbar. Here i am using bottom navigation to change the fragments. Each and every fragment i want to set different title and image. I have to set title as center of the toolbar and back button as right corner of the toolbar.
In your MainActivity add these lines in OnCreate() method
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle("My Activity Title");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
To use Back arrow you can write this code outside onCreate()
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
Toast.makeText(this, "Back button pressed", Toast.LENGTH_SHORT).show();
return true;
}
return super.onOptionsItemSelected(item);
}
In you fragment you can change title of Toolbar
getActivity().setTitle("My fragment Title");
You can Create custom Toolbar with ImageView and TextView with your arrow .
include_tool_bar.xml
<com.mastercard.wallet.ui.widget.CustomTextView
android:id="#+id/toolbar_title"
style="#style/Toolbar.TitleText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|left"
android:textSize="#dimen/px_48"
app:fontName="InterStateLight"
customviews:fontName="InterStateLight" />
<ImageView
android:id="#+id/toolbar_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="#string/adaCitiPayLogoText"
android:src="#drawable/ab_logo"
android:visibility="gone" />
And Add Toolbar
Toolbar toolbar = (Toolbar) appCompatActivity.findViewById(R.id.toolbar);
ImageView logo = (ImageView) toolbar.findViewById(R.id.toolbar_logo);
CustomTextView textView = (CustomTextView) toolbar.findViewById(R.id.toolbar_title);
logo.setVisibility(View.VISIBLE);
logo.setImageResource(logoResourceId);
textView.setVisibility(View.GONE);
appCompatActivity.setSupportActionBar(toolbar);
appCompatActivity.getSupportActionBar().setDisplayShowTitleEnabled(false);
title of the toolbar can be changed from fragment calling this in onActivityCreated
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
((MainActivity) getActivity()).getSupportActionBar().setTitle(getString(R.string.menu_about_us));
((MainActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
((MainActivity) getActivity()).getSupportActionBar().setDisplayShowHomeEnabled(true);
}
in your activity make sure to add a toolbar like this.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
and set it in your activity
setSupportActionBar(findViewById(R.id.toolbar));
and for the back press just add a listener and do the needful.
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_action_back));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// pop up fragment or take another action
}
});

CardView selector?

I'm creating a notes app and I'm using a contextual action bar to delete notes. I have my notes displayed in a card view. I have the action bar working to the point where I can select notes and delete them. But when I select notes I want to use a checkmark as a selector if possible (otherwise any selector) which I have been unsuccessful in achieving.
contextual action bar
mListViewNotes = (ListView) findViewById(R.id.listview_notes);
mListViewNotes.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
mListViewNotes.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
CardView cardView = (CardView) findViewById(R.id.cardView);
#Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
if (list_items.contains(notes.get(position))) {
count = count-1;
list_items.remove(notes.get(position));
mode.setTitle(count + " Notes Selected");
} else {
count = count+1;
list_items.add(notes.get(position));
mode.setTitle(count + " Notes Selected");
}
if (count == 0) {
mode.setTitle("No Notes Selected");
}
}
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
app_bar.setVisibility(View.GONE);
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
actionMode = mode;
return true;
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
deleteNote();
return true;
}
#Override
public void onDestroyActionMode(ActionMode mode) {
count = 0;
app_bar.setVisibility(View.VISIBLE);
list_items.clear();
}
});
}
item_note.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/light_sand"
android:orientation="vertical"
android:id="#+id/item_note">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_gravity="center"
android:layout_marginBottom="6dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="6dp"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="6dp">
<ImageView
android:layout_width="1000dp"
android:layout_height="150dp"
android:layout_gravity="start"
android:layout_marginLeft="-80dp"
android:layout_marginTop="-12dp"
android:background="#drawable/texture_tile_old"
android:scaleType="fitStart" />
<ImageView
android:id="#+id/clef_note"
android:layout_width="70dp"
android:layout_height="120dp"
android:layout_gravity="start"
android:layout_marginTop="10dp"
android:background="#drawable/treble_clef" />
<View
android:layout_width="780dp"
android:layout_height="1dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="43dp"
android:background="#color/black" />
<View
android:layout_width="780dp"
android:layout_height="1dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="70dp"
android:background="#color/black" />
<View
android:layout_width="780dp"
android:layout_height="1dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="97dp"
android:background="#color/black" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:scaleType="center">
<TextView
android:id="#+id/list_note_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="65dp"
android:layout_marginTop="8dp"
android:textColor="#color/black"
android:textSize="28sp" />
<TextView
android:id="#+id/list_note_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="46dp"
android:layout_marginLeft="65dp"
android:layout_marginTop="0dp"
android:maxLines="2"
android:textColor="#color/gunmetal"
android:textSize="20sp"
android:lineSpacingExtra="4dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/brown"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="Last Updated:"
android:textColor="#color/white" />
<TextView
android:id="#+id/list_note_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:gravity="end"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/white" />
</LinearLayout>
</android.support.v7.widget.CardView>
You can add a CheckBox to your item layout, and/or change the background of the layout itself to display a selected state.
With the first option, you can change the layout to the selected state just by setting the isChecked to true.
checkBox.setChecked(true);
To change the background of the layout, you can simply set the background to a new color resource.
itemLayout.setBackgroundResource(R.color.color_selected);
Or you can use a ColorStateList to do some more advanced state changes (such as a ripple effect to a solid color).
ripple_selector.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/color_highlight">
<item android:drawable="#drawable/color_highlight"/>
</ripple>
item_selector_background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="#color/color_selected"/>
<item android:drawable="#drawable/ripple_effect"/>
</selector>
To use this, you can set the background attribute in your layout xml to item_selector_background then changed the selected state in your code.
itemLayout.setSelected(true);
MaterialCardView can be a good solution. result
<com.google.android.material.card.MaterialCardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:strokeWidth="4dp"
app:rippleColor="#color/colorPrimary"
app:strokeColor="#color/colorAccent"
app:cardCornerRadius="#dimen/margin_app"
app:cardBackgroundColor="#android:color/white">
<androidx.constraintlayout.widget.ConstraintLayout
android:paddingVertical="#dimen/margin_large"
android:paddingHorizontal="#dimen/margin_xlarge"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

How to show shopping cart icon in activity?

I made the shopping cart app and I use the navigation drawer and in this navigation drawer I use the shopping cart icon.
Now, When i click on the particular item. It's open in new activity but its not showing the shopping cart icon, So how will it show? So,i see the item in the cart?
ItemDetailsActivity. java (This is the .java file of this image where i am unable to see the shopping cart icon, so i am unable to see how many items add in the cart)
public class ItemDetailsActivity extends AppCompatActivity {
int imagePosition;
String stringImageUri;
TextView textViewshare, textViewmap;
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_details);
SimpleDraweeView mImageView = (SimpleDraweeView)findViewById(R.id.image1);
TextView textViewAddToCart = (TextView)findViewById(R.id.text_action_bottom1);
TextView textViewBuyNow = (TextView)findViewById(R.id.text_action_bottom2);
textViewshare = (TextView) findViewById(R.id.text_action1);
textViewmap = (TextView) findViewById(R.id.text_action3);
TextView textViewBuyNowwithpayment = (TextView) findViewById(R.id.text_action_bottom2);
//Getting image uri from previous screen
if (getIntent() != null) {
stringImageUri = getIntent().getStringExtra(ImageListFragment.STRING_IMAGE_URI);
imagePosition = getIntent().getIntExtra(ImageListFragment.STRING_IMAGE_URI,0);
}
Uri uri = Uri.parse(stringImageUri);
mImageView.setImageURI(uri);
mImageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(ItemDetailsActivity.this, ViewPagerActivity.class);
intent.putExtra("position", imagePosition);
startActivity(intent);
}
});
textViewAddToCart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ImageUrlUtils imageUrlUtils = new ImageUrlUtils();
imageUrlUtils.addCartListImageUri(stringImageUri);
Toast.makeText(ItemDetailsActivity.this,"Item added to cart.",Toast.LENGTH_SHORT).show();
MainActivity.notificationCountCart++;
NotificationCountSetClass.setNotifyCount(MainActivity.notificationCountCart);
}
});
textViewBuyNow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ImageUrlUtils imageUrlUtils = new ImageUrlUtils();
imageUrlUtils.addCartListImageUri(stringImageUri);
MainActivity.notificationCountCart++;
NotificationCountSetClass.setNotifyCount(MainActivity.notificationCountCart);
startActivity(new Intent(ItemDetailsActivity.this, CartListActivity.class));
}
});
// payment.setOnClickListener(new View.OnClickListener() {
// #Override
// public void onClick(View v) {
// Intent i = new Intent(ItemDetailsActivity.this, PayPalCheckoutActivity.class);
// startActivity(i);
// }
// });
textViewBuyNowwithpayment.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(ItemDetailsActivity.this, PayPalCheckoutActivity.class);
startActivity(i);
}
});
textViewshare.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "SUBJECT");
intent.putExtra(Intent.EXTRA_TEXT,"Extra Text");
startActivity(intent);
}
});
textViewmap.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent in = new Intent(ItemDetailsActivity.this, Placepicker.class);
startActivity(in);
}
});
}
}
activity_item_details.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/activity_item_details"
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:orientation="vertical"
android:weightSum="10"
tools:context="com.codeexpertise.eshop.product.ItemDetailsActivity">
<ScrollView android:id="#+id/scrollbar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9.5"
android:scrollbars="none"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.facebook.drawee.view.SimpleDraweeView xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:id="#+id/image1"
android:layout_width="match_parent"
android:layout_height="200.0dp"
fresco:placeholderImage="#color/stay_color" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:orientation="vertical">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Denim Shirt"
android:textSize="16dp"
android:textColor="#color/gen_black"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Rs. 1,979"
android:textSize="20dp"
android:textColor="#color/gen_black"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FREE Delivery"
android:textSize="12dp"
android:layout_marginTop="4dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="8dp">
<TextView android:id="#+id/text_ratings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/green_light"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:text="4.3 *"
android:textSize="12dp"
android:textColor="#color/gen_white"
android:textStyle="bold"/>
<TextView android:id="#+id/text_ratings_reviews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:text="50 ratings \u0026 15 reviews"
android:textSize="12dp"/>
</LinearLayout>/
<View android:layout_width="match_parent"
android:layout_height="#dimen/view_width_small"
android:background="#color/grey_light"
android:layout_marginTop="8dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:layout_marginTop="8dp"
android:weightSum="3">
<LinearLayout android:id="#+id/layout_action1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_share_black_18dp"/>
<TextView android:id="#+id/text_action1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:text="Share"
android:showAsAction="ifRoom"
android:textSize="12dp"
android:textColor="#color/gen_black"
android:gravity="left"
android:actionProviderClass=
"android.widget.ShareActionProvider"/>
</LinearLayout>
<View android:layout_width="#dimen/view_width_small"
android:layout_height="match_parent"
android:background="#color/grey_light"/>
<LinearLayout android:id="#+id/layout_action2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_filter_none_black_18dp"/>
<TextView android:id="#+id/text_action2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:text="Similar"
android:textSize="12dp"
android:textColor="#color/gen_black"
android:gravity="left"/>
</LinearLayout>
<View android:layout_width="#dimen/view_width_small"
android:layout_height="match_parent"
android:background="#color/grey_light"/>
<LinearLayout android:id="#+id/layout_action3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_favorite_border_black_18dp"/>
<TextView android:id="#+id/text_action3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_marginLeft="8dp"
android:text="Store Locator"
android:textSize="12dp"
android:textColor="#color/gen_black"
android:gravity="left"/>
</LinearLayout>
</LinearLayout>
<View android:layout_width="match_parent"
android:layout_height="#dimen/view_width_small"
android:background="#color/grey_light"
android:layout_marginTop="8dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Details"
android:textSize="16dp"
android:textColor="#color/gen_black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="\u2022 Regular fit, full sleeve"
android:textSize="12dp"
android:textColor="#color/gen_black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="\u2022 Fabric: Cotton"
android:textSize="12dp"
android:textColor="#color/gen_black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="\u2022 Pattern: printed"
android:textSize="12dp"
android:textColor="#color/gen_black"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="horizontal"
android:weightSum="2"
android:elevation="30dp"
android:background="#color/gen_black">
<TextView android:id="#+id/text_action_bottom1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/gen_white"
android:text="ADD TO CART"
android:textSize="14dp"
android:textColor="#color/gen_black"
android:textStyle="bold"
android:gravity="center"/>
<TextView android:id="#+id/text_action_bottom2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#4dc3ff"
android:text="BUY NOW"
android:textSize="14dp"
android:textColor="#color/gen_white"
android:textStyle="bold"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
Main.xml (In this xml i use the menu item which show in navigation drawer bar)
<?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/action_search"
android:title="#string/action_search"
android:icon="#drawable/ic_search_white_24dp"
app:showAsAction="collapseActionView|ifRoom"
app:actionViewClass="android.support.v7.widget.SearchView"/>
<item android:id="#+id/action_notifications"
android:title="#string/action_notifications"
app:showAsAction="always"
android:icon="#drawable/ic_notifications_white_24dp"/>
<item android:id="#+id/action_cart"
android:title="#string/action_cart"
app:showAsAction="always"
android:icon="#drawable/ic_menu_notifications"/>
</menu>
Please Override this Method in your ItemDetailsActivity to Show Menu
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
verride this Method in your ItemDetailsActivity to Handle Click Events
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_cart:
dosomething();
return true;
default:
return super.onOptionsItemSelected(item);
}
}

Navigation drawer cannot set text and image

Case_history_review.java
This is one of my java to use the nav bar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("E-care");
setSupportActionBar(toolbar);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView view = (NavigationView) findViewById(R.id.navigation_view);
view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
Toast.makeText(Case_history_review.this, menuItem.getItemId() + " pressed", Toast.LENGTH_LONG).show();
Log.d(R.id.nav_1+"", menuItem.getItemId() + " ");
Intent intent = new Intent();
switch (menuItem.getItemId())
{
case R.id.nav_1:
break;
case R.id.nav_2:
intent.setClass(Case_history_review.this,queueshow.class);
//intent .putExtra("name", "Hello B Activity");
startActivity(intent);
break;
case R.id.nav_3:
intent.setClass(Case_history_review.this,Appointmentcreate.class);
//intent .putExtra("name", "Hello B Activity");
startActivity(intent);
break;
case R.id.nav_4:
intent.setClass(Case_history_review.this, AlarmActivity.class);
startActivity(intent);
break;
case R.id.nav_5:
intent.setClass(Case_history_review.this, PatientReport.class);
startActivity(intent);
break;
case R.id.nav_6:
intent.setClass(Case_history_review.this, TimeList.class);
startActivity(intent);
//logout
break;
}
menuItem.setChecked(true);
drawerLayout.closeDrawers();
return true;
}
});
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle( this, drawerLayout, toolbar, R.string.drawer_open , R.string.drawer_close){
#Override
public void onDrawerClosed(View drawerView) {
super .onDrawerClosed(drawerView);
}
#Override
public void onDrawerOpened(View drawerView) {
super .onDrawerOpened(drawerView);
}
};
db = new SQLiteHandler(getApplicationContext());
HashMap<String, String> dbuser = db.getUserDetails();
TextView name = (TextView) view.findViewById(R.id.drawer_name);
String username = dbuser.get("name");
Log.d("naem",username);
name.setText(username);
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
CirculaireNetworkImageView photo = (CirculaireNetworkImageView) view.findViewById(R.id.drawer_thumbnail);
photo.setImageUrl("http://192.168.43.216/test/" + dbuser.get("image"), imageLoader);
drawerLayout.setDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();
These two lines get errors
name.setText(username);
photo.setImageUrl("http://192.168.43.216/test/" + dbuser.get("image"), imageLoader);
Error message:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.yuen.e_carei.Case_history_review.onCreate(Case_history_review.java:116)
layout/drawer_header.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#0097a7"
>
<com.example.yuen.CirculaireNetworkImageView
android:id="#+id/drawer_thumbnail"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="8dp"
android:elevation="8dp"
android:layout_above="#+id/drawer_name"
android:layout_alignStart="#+id/drawer_name" />
<TextView
android:id="#+id/drawer_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:layout_alignParentBottom="true"
android:text="Eddard Stark"
android:textSize="14sp"
android:textColor="#fff"
android:textStyle="bold"
android:paddingBottom="8dp"
/>
</RelativeLayout>
menu/drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_1"
android:checked="true"
android:icon="#drawable/hi"
android:title="Case Review"/>
<item
android:id="#+id/nav_2"
android:icon="#drawable/hi"
android:title="Queue state"/>
<item
android:id="#+id/nav_3"
android:icon="#drawable/hi"
android:title="Create appointemnt"/>
<item
android:id="#+id/nav_4"
android:icon="#drawable/hi"
android:title="Alarm"/>
<item
android:id="#+id/nav_5"
android:icon="#drawable/hi"
android:title="Report"/>
<item
android:id="#+id/nav_6"
android:icon="#drawable/hi"
android:title="Logout"/>
</group>
</menu>
activity_case_history_solo.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.yuen.e_carei.Case_history_review">
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- your content layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.yuen.e_carei.Case_history_review">
<ImageView
android:src="#drawable/hi"
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView2"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/imageView2"
android:layout_alignBottom="#+id/imageView2"
android:id="#+id/relativeLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name : "
android:textSize="25sp"
android:id="#+id/textView2"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ID : "
android:textSize="25sp"
android:id="#+id/idTag"
android:paddingLeft="11dp"
android:layout_below="#+id/textView2"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chan Tai Man"
android:textSize="25sp"
android:id="#+id/nameResult"
android:paddingBottom="10dp"
android:layout_above="#+id/idResult"
android:layout_toEndOf="#+id/textView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="N001"
android:textSize="25sp"
android:id="#+id/idResult"
android:layout_below="#+id/textView2"
android:layout_toEndOf="#+id/idTag" />
</RelativeLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView_case_history"
android:layout_alignEnd="#+id/relativeLayout"
android:layout_below="#+id/imageView2" />
</RelativeLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
app:menu="#menu/drawer" />
</android.support.v4.widget.DrawerLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
I want to change the text in the drawer_header to become other string. However, it can get the id but crash in the runtime. Please give me some helps to solve this. Thank You.
Error depicts that the TextView object is null, means there is no such textview exists in the layout that is currently running.
Did the textview present in the XML layout that you are calling? Which layout did you put the TextView?
Kindly check whether your activity is correct!!
The id that you use inside findViewById(R.id....) may be wrong. Double check that.
You have called the
TextView name = (TextView) view.findViewById(R.id.drawer_name);
in the Case_history_review.java but it seems that the above textView doesn't exists in your layout that you are calling. Probably you will be calling the below activity_case_history_solo.XML in the Activity and it doesn't has it. And the above TextView lies in the drawer_header.xml
Hope this helps you..!!

ActionBar hidden when starting fragment

I have an activity that correctly displays my ActionBar and it's items, however when I try to add a fragment to that activity the ActionBar disappears when that fragment is launched, or if I try to include the ActionBar it shows the bar but no title or MenuOptions.
Want I am trying to achieve is one activity, with the same ActionBar for all fragments, unless specified otherwise.
MainActivity.Java
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final HomeFragment homeFragment = new HomeFragment();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
if (savedInstanceState == null) {
getFragmentManager()
.beginTransaction()
.add(R.id.main_container, homeFragment)
.addToBackStack(null)
.commit();
}
}
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_activity_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
} else if (id == R.id.search_mag_icon){
// Open intent here
Intent i = new Intent(getApplicationContext(), SearchActivity.class);
startActivity(i);
}
return super.onOptionsItemSelected(item);
}
HomeFragment.java
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Book icon and text -->
<ImageView
android:id="#+id/bookIcon"
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_marginLeft="50dip"
android:layout_marginTop="110dip"
android:src="#drawable/book" />
<TextView
android:id="#+id/bookLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/bookIcon"
android:layout_marginLeft="20dip"
android:text="#string/bookLabel"
android:textColor="#color/colorAlt"
android:textStyle="bold" />
<!-- Barcode icon and text -->
<ImageView
android:id="#+id/barcodeIcon"
android:layout_width="95dip"
android:layout_height="95dip"
android:layout_marginLeft="260dip"
android:layout_marginTop="120dip"
android:src="#drawable/barcode" />
<TextView
android:id="#+id/barcodeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/barcodeIcon"
android:layout_marginLeft="260dip"
android:paddingTop="5dip"
android:text="#string/barcodeLabel"
android:textColor="#color/colorAlt"
android:textStyle="bold" />
<!-- Message icon and text -->
<ImageView
android:id="#+id/messageIcon"
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_marginLeft="50dip"
android:layout_marginTop="350dip"
android:src="#drawable/email" />
<TextView
android:id="#+id/messageLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/messageIcon"
android:layout_marginLeft="55dip"
android:text="#string/messageLabel"
android:textColor="#color/colorAlt"
android:textStyle="bold" />
<!-- List icon and text -->
<ImageView
android:id="#+id/listIcon"
android:layout_width="95dip"
android:layout_height="95dip"
android:layout_marginLeft="260dip"
android:layout_marginTop="350dip"
android:src="#drawable/list" />
<TextView
android:id="#+id/listLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/listIcon"
android:layout_marginLeft="273dip"
android:paddingTop="5dip"
android:text="#string/listLabel"
android:textColor="#color/colorAlt"
android:textStyle="bold" />
</RelativeLayout>
</FrameLayout>
activity_main
<?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/drawer_layout"
android:background="#FFF"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="#layout/app_bar_main" />
<FrameLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:background="#color/colorPrimaryDark"
app:itemTextColor="#FFF"
app:itemIconTint="#FFF"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
fragment_home.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<include layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Book icon and text -->
<ImageView
android:id="#+id/bookIcon"
android:src="#drawable/book"
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_marginLeft="50dip"
android:layout_marginTop = "110dip"
/>
<TextView
android:id="#+id/bookLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/bookLabel"
android:textColor="#color/colorAlt"
android:textStyle="bold"
android:layout_marginLeft="20dip"
android:layout_below="#+id/bookIcon" />
<!-- Barcode icon and text -->
<ImageView
android:id="#+id/barcodeIcon"
android:src="#drawable/barcode"
android:layout_width="95dip"
android:layout_height="95dip"
android:layout_marginLeft="260dip"
android:layout_marginTop = "120dip"
/>
<TextView
android:id="#+id/barcodeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/barcodeLabel"
android:textColor="#color/colorAlt"
android:textStyle="bold"
android:layout_below="#+id/barcodeIcon"
android:paddingTop="5dip"
android:layout_marginLeft="260dip"/>
<!-- Message icon and text -->
<ImageView
android:id="#+id/messageIcon"
android:src="#drawable/email"
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_marginLeft="50dip"
android:layout_marginTop = "350dip"
/>
<TextView
android:id="#+id/messageLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/messageLabel"
android:textColor="#color/colorAlt"
android:textStyle="bold"
android:layout_marginLeft="55dip"
android:layout_below="#+id/messageIcon" />
<!-- List icon and text -->
<ImageView
android:id="#+id/listIcon"
android:src="#drawable/list"
android:layout_width="95dip"
android:layout_height="95dip"
android:layout_marginLeft="260dip"
android:layout_marginTop = "350dip"
/>
<TextView
android:id="#+id/listLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/listLabel"
android:textColor="#color/colorAlt"
android:textStyle="bold"
android:layout_below="#+id/listIcon"
android:paddingTop="5dip"
android:layout_marginLeft="273dip"/>
</RelativeLayout>
Thank you for any help in advance.
modify layout
Put you ToolBar inside LinearLayout and Change Fragment with FrameLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="#layout/app_bar_main" />
<FrameLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
call Fragment from Activity
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.replace(R.id.main_container,homeFragment));
fragmentTransaction.commit();

Categories