Skip to content
Snippets Groups Projects
Commit 8c2910a2 authored by Xavier Gibert's avatar Xavier Gibert
Browse files

NavigationDrawer styled

parent 1f616013
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp" android:topLeftRadius="0dp" android:bottomLeftRadius="0dp"/>
<padding android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp"/>
<!-- <solid android:color="#2D2D2D"/> -->
<gradient
android:startColor="#2D2D2D"
android:endColor="#4D4D4D"
android:angle="90" />
<stroke
android:width="2dp"
android:color="#545454" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp" android:topLeftRadius="0dp" android:bottomLeftRadius="0dp"/>
<!-- <solid android:color="#000000"/> -->
<gradient
android:startColor="#000000"
android:endColor="#202020"
android:angle="90" />
<stroke
android:width="2dp"
android:color="#545454" />
</shape>
\ No newline at end of file
......@@ -3,9 +3,10 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.8"
android:background="@color/navigation"
android:background="@color/black"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:dividerHeight="2dp"
android:drawSelectorOnTop="false"
tools:context="fragments.NavigationDrawerFragment" />
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android1:id="@+id/nav_item_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/navigation_section"
android1:textAppearance="?android:attr/textAppearanceLarge" >
</TextView>
......@@ -242,6 +242,10 @@ public class MainActivity extends ActionBarActivity implements
});
}
public void showSection() {
showSection(mNavigationDrawerFragment.getSelectedPosition());
}
private Toast toast;
private long lastBackPressTime = 0;
......@@ -267,7 +271,7 @@ public class MainActivity extends ActionBarActivity implements
}
}
}else{
mNavigationDrawerFragment.select();
showSection();
}
}
......
......@@ -15,6 +15,7 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Bitmap;
......@@ -30,6 +31,7 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
/**
......@@ -110,26 +112,65 @@ public class NavigationDrawerFragment extends Fragment {
mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//XGGDEBUG
//First update the previously selected item if one has been set
/*if(selectedListItem!=null){
TextView previousTitle = (TextView) selectedListItem.findViewById(R.id.nav_item_text);
previousTitle.setBackgroundResource(R.drawable.navigation_section);
}
//Then update the new one
TextView title = (TextView) view.findViewById(R.id.nav_item_text);
title.setBackgroundResource(R.drawable.navigation_selector);
selectedListItem = view;
*/
selectItem(position);
}
});
mDrawerListView.setAdapter(new ArrayAdapter<String>(
getActionBar().getThemedContext(),
android.R.layout.simple_list_item_1,
android.R.id.text1,
R.layout.nav_item,
R.id.nav_item_text,
new String[]{
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3),
getString(R.string.title_section4),
getString(R.string.title_section5),
getString(R.string.title_section6),
getString(R.string.title_section7),
}));
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3),
getString(R.string.title_section4),
getString(R.string.title_section5),
getString(R.string.title_section6),
getString(R.string.title_section7),
}){
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.nav_item, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.nav_item_text);
String[] values = new String[]{
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3),
getString(R.string.title_section4),
getString(R.string.title_section5),
getString(R.string.title_section6),
getString(R.string.title_section7),
};
textView.setText(values[position]);
if (position == mCurrentSelectedPosition)
{
textView.setBackgroundResource(R.drawable.navigation_selector);
}else{
textView.setBackgroundResource(R.drawable.navigation_section);
}
return rowView;
}
});
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
return mDrawerListView;
}
public boolean isDrawerOpen() {
return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView);
}
......@@ -210,16 +251,34 @@ public class NavigationDrawerFragment extends Fragment {
public void select(int position){
selectItem(position);
//setCorrectBackgrounds();
}
public void select() {
selectItem(mCurrentSelectedPosition);
}
/*private void setCorrectBackgrounds(){
for(int i=0; i<mDrawerListView.getChildCount(); i++){
if(mCurrentSelectedPosition==i)
((TextView)mDrawerListView.getChildAt(i)).setBackgroundResource(R.drawable.navigation_selector);
else
((TextView)mDrawerListView.getChildAt(i)).setBackgroundResource(R.drawable.navigation_section);
}
}*/
private void selectItem(int position) {
mCurrentSelectedPosition = position;
if (mDrawerListView != null) {
mDrawerListView.setItemChecked(position, true);
}
} public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//XGGDEBUG
//First update the previously selected item if one has been set
/*if(selectedListItem!=null){
TextView previousTitle = (TextView) selectedListItem.findViewById(R.id.nav_item_text);
previousTitle.setBackgroundResource(R.drawable.navigation_section);
}
//Then update the new one
TextView title = (TextView) view.findViewById(R.id.nav_item_text);
title.setBackgroundResource(R.drawable.navigation_selector);
selectedListItem = view;
*/
if (mDrawerLayout != null) {
mDrawerLayout.closeDrawer(mFragmentContainerView);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment