Last Updated
Viewed 23 Times
     

I'm using Android Studio 3.5

I have found some old project on stack overflow that no longer works:

Multiple Tab fragments inside bottom navigation fragment

How to use tablayout with bottom navigation and viewpager?

I really need this kind of layout, but I can't find any useful resources to help me build the project.

Please help me out this is my current state: https://github.com/ericbig66/Tabbed-layou-inside-bottom-navigation

This is the result I want to achieve

how can i add an image header to my navigation drawer layout like this one. the problem i now have is that every listitem has it's own icon but the header image is also printed on every item.

this is what i want enter image description here

What i now have is this: this is what i have now enter image description here

mainactivity.java

main activity.java

package be.yvandamme.ginlovers.activity;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.google.android.gms.analytics.GoogleAnalytics;
import be.yvandamme.ginlovers.R;
import be.yvandamme.ginlovers.WebViewAppApplication;
import be.yvandamme.ginlovers.adapter.DrawerAdapter;
import be.yvandamme.ginlovers.fragment.MainFragment;


public class MainActivity extends ActionBarActivity
{
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private ListView mDrawerListView;

private CharSequence mTitle;
private CharSequence mDrawerTitle;
private String[] mTitles;


public static Intent newIntent(Context context)
{
    Intent intent = new Intent(context, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    return intent;
}


@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setupActionBar();
    setupDrawer(savedInstanceState);

    // init analytics tracker
    ((WebViewAppApplication) getApplication()).getTracker();
}


@Override
public void onStart()
{
    super.onStart();

    // analytics
    GoogleAnalytics.getInstance(this).reportActivityStart(this);
}


@Override
public void onResume()
{
    super.onResume();
}


@Override
public void onPause()
{
    super.onPause();
}


@Override
public void onStop()
{
    super.onStop();

    // analytics
    GoogleAnalytics.getInstance(this).reportActivityStop(this);
}


@Override
public void onDestroy()
{
    super.onDestroy();
}


@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    // action bar menu
    return super.onCreateOptionsMenu(menu);
}


@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    // open or close the drawer if home button is pressed
    if(mDrawerToggle.onOptionsItemSelected(item))
    {
        return true;
    }

    // action bar menu behaviour
    switch(item.getItemId())
    {
        case android.R.id.home:
            Intent intent = MainActivity.newIntent(this);
            startActivity(intent);
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }
}


@Override
protected void onPostCreate(Bundle savedInstanceState)
{
    super.onPostCreate(savedInstanceState);
    mDrawerToggle.syncState();
}


@Override
public void onConfigurationChanged(Configuration newConfiguration)
{
    super.onConfigurationChanged(newConfiguration);
    mDrawerToggle.onConfigurationChanged(newConfiguration);
}


@Override
public void setTitle(CharSequence title)
{
    mTitle = title;
    getSupportActionBar().setTitle(mTitle);
}


private void setupActionBar()
{
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar bar = getSupportActionBar();
    bar.setDisplayUseLogoEnabled(false);
    bar.setDisplayShowTitleEnabled(true);
    bar.setDisplayShowHomeEnabled(true);
    bar.setDisplayHomeAsUpEnabled(true);
    bar.setHomeButtonEnabled(true);
}


private void setupDrawer(Bundle savedInstanceState)
{
    mTitle = getTitle();
    mDrawerTitle = getTitle();

    // title list
    mTitles = getResources().getStringArray(R.array.navigation_title_list);

    // icon list
    TypedArray iconTypedArray =    getResources().obtainTypedArray(R.array.navigation_icon_list);
    Integer[] icons = new Integer[iconTypedArray.length()];
    for(int i=0; i<iconTypedArray.length(); i++)
    {
        icons[i] = iconTypedArray.getResourceId(i, -1);
    }
    iconTypedArray.recycle();

    // reference
    mDrawerLayout = (DrawerLayout) findViewById(R.id.activity_main_layout);
    mDrawerListView = (ListView) findViewById(R.id.activity_main_drawer);

    // set drawer
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    mDrawerListView.setAdapter(new DrawerAdapter(this, mTitles, icons));
    mDrawerListView.setOnItemClickListener(new OnItemClickListener()
    {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View clickedView, int position, long id)
        {
            selectDrawerItem(position, false);
        }
    });
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close)
    {
        @Override
        public void onDrawerClosed(View view)
        {
            getSupportActionBar().setTitle(mTitle);
            supportInvalidateOptionsMenu();
        }

        @Override
        public void onDrawerOpened(View drawerView)
        {
            getSupportActionBar().setTitle(mDrawerTitle);
            supportInvalidateOptionsMenu();
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    // show initial fragment
    if(savedInstanceState == null)
    {
        selectDrawerItem(0, true);
    }
}


private void selectDrawerItem(int position, boolean init)
{
    String[] urlList = getResources().getStringArray(R.array.navigation_url_list);
    String[] shareList = getResources().getStringArray(R.array.navigation_share_list);

    Fragment fragment = MainFragment.newInstance(urlList[position], shareList[position]);
    FragmentManager fragmentManager = getSupportFragmentManager();
      fragmentManager.beginTransaction().replace(R.id.activity_main_container, fragment).commitAllowingStateLoss();

    mDrawerListView.setItemChecked(position, true);
    if(!init) setTitle(mTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerListView);
}
}

drawer adapter.java

package be.yvandamme.ginlovers.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import be.yvandamme.ginlovers.R;


public class DrawerAdapter extends BaseAdapter
{
private Context mContext;
private String[] mTitleList;
private Integer[] mIconList;


public DrawerAdapter(Context context, String[] titleList, Integer[] iconList)
{
    mContext = context;
    mTitleList = titleList;
    mIconList = iconList;
}


@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
    // inflate view
    View view = convertView;
    if(view == null) 
    {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.drawer_item, parent, false);

        // view holder
        ViewHolder holder = new ViewHolder();
        holder.titleTextView = (TextView) view.findViewById(R.id.drawer_item_title);
        holder.iconImageView = (ImageView) view.findViewById(R.id.drawer_item_icon);
        view.setTag(holder);
    }

    // entity
    String title = mTitleList[position];
    Integer icon = mIconList[position];

    if(title!=null && icon!=null )
    {
        // view holder
        ViewHolder holder = (ViewHolder) view.getTag();

        // content
        holder.titleTextView.setText(title);
        holder.iconImageView.setImageResource(icon);
    }

    return view;
}


@Override
public int getCount()
{
    if(mTitleList!=null) return mTitleList.length;
    else return 0;
}


@Override
public Object getItem(int position)
{
    if(mTitleList!=null) return mTitleList[position];
    else return null;
}


@Override
public long getItemId(int position)
{
    return position;
}


public void refill(Context context, String[] titleList, Integer[] iconList)
{
    mContext = context;
    mTitleList = titleList;
    mIconList = iconList;
    notifyDataSetChanged();
}


static class ViewHolder
{
    TextView titleTextView;
    ImageView iconImageView;
}
}

this is my activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include layout="@layout/toolbar" />

<android.support.v4.widget.DrawerLayout
    android:id="@+id/activity_main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/activity_main_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

    </FrameLayout>

    <ListView
        android:id="@+id/activity_main_drawer"
        android:layout_width="@dimen/drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:drawSelectorOnTop="true"
        android:fastScrollEnabled="false"
        android:listSelector="@drawable/selector_clickable_item_bg"
        android:background="@color/global_bg_front"
        />

</android.support.v4.widget.DrawerLayout>

</LinearLayout>

and this my drawer_item.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="wrap_content"
android:minHeight="@dimen/global_spacing_l"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="?attr/drawerItemBackground">



<ImageView
    android:id="@+id/drawer_image"
    android:layout_width="280dp"
    android:layout_height="140dp"
    android:src="@drawable/loading" />


<ImageView
    android:id="@+id/drawer_item_icon"
    android:layout_width="@dimen/global_spacing_m"
    android:layout_height="@dimen/global_spacing_m"
    android:layout_marginLeft="@dimen/global_keyline_s"
    android:layout_marginRight="@dimen/global_spacing_xs"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter"
    android:layout_below="@+id/drawer_image"/>


<TextView
    android:id="@+id/drawer_item_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="@dimen/global_keyline_s"
    android:textAppearance="@style/TextAppearance.WebViewApp.Body1"
    android:layout_below="@+id/drawer_image"/>

</RelativeLayout>

I have a list view in my app and to the bottom of the list view i need to add to buttons but it should be above that the listview with less colored transparent background

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="#b5b5b5"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector" >
    </ListView>

</LinearLayout>

I have an navigation app and I want to make share item work I used this code but it does not work

public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_download) {
        // Handle the camera action
    } else if (id == R.id.nav_favorite) {

    } else if (id == R.id.nav_allstories) {

    } else if (id == R.id.nav_share) {

        id.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent myIntent = new Intent(Intent.ACTION_SEND);
                myIntent.setType("text/plain");
                String shareBody="Your Body Here";
                String shareSub="Your Subject Here";
                myIntent.putExtra(Intent.EXTRA_SUBJECT,shareSub);
                myIntent.putExtra(Intent.EXTRA_TEXT,shareBody);
                startActivity(Intent.createChooser(myIntent,"Share using"));

            }
        });

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

I do not know how can I reach to the item. I also tried ShareView but I think the android does not supported or something like this.

Similar Question 4 (1 solutions) : How can i add border to bottom of image?

Similar Question 8 (1 solutions) : How to add Tablayout icons

Similar Question 9 (2 solutions) : how to add bottom layout in Modal BottomSheet Dialog?

cc