Merge "Add NavigationView usage to SupportDesignDemos" into lmp-mr1-ub-dev

This commit is contained in:
Yuichi Araki
2015-04-15 02:58:27 +00:00
committed by Android (Google) Code Review
17 changed files with 348 additions and 0 deletions

View File

@@ -45,6 +45,15 @@
</intent-filter>
</activity>
<activity android:name=".widget.NavigationViewUsage"
android:label="@string/design_navigation"
android:theme="@style/Theme.Navigation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.support.design.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".widget.TabLayoutUsage"
android:label="@string/design_tabs_basic"
android:theme="@style/Theme.Design">

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 557 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<TextView
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/navigation_1"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="180dp"
android:padding="16dp"
android:background="?attr/colorPrimary"
android:gravity="bottom|start"
android:text="@string/navigation_header"
android:textAppearance="?android:attr/textAppearanceLargeInverse"/>

View File

@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Main items -->
<group android:checkableBehavior="single">
<item
android:id="@+id/navigation_item_1"
android:checked="true"
android:icon="@drawable/ic_android"
android:title="@string/navigation_item_1"/>
<item
android:id="@+id/navigation_item_2"
android:icon="@drawable/ic_android"
android:title="@string/navigation_item_2"/>
<item
android:id="@+id/navigation_item_3"
android:icon="@drawable/ic_android"
android:title="@string/navigation_item_3"/>
<item
android:id="@+id/navigation_item_disabled"
android:icon="@drawable/ic_android"
android:title="@string/navigation_item_4"
android:enabled="false"/>
<item
android:id="@+id/navigation_invisible"
android:icon="@drawable/ic_android"
android:title="@string/navigation_invisible"
android:visible="false"/>
</group>
<item
android:id="@+id/navigation_subheader"
android:title="@string/navigation_subheader">
<menu>
<item
android:id="@+id/navigation_sub_item_1"
android:icon="@drawable/ic_android"
android:title="@string/navigation_sub_item_1"/>
<item
android:id="@+id/navigation_sub_item_2"
android:icon="@drawable/ic_android"
android:title="@string/navigation_sub_item_2"/>
</menu>
</item>
<group android:id="@+id/aligned_items">
<item
android:id="@+id/navigation_with_icon"
android:icon="@drawable/ic_android"
android:title="@string/navigation_item_with_icon"/>
<item
android:id="@+id/navigation_without_icon"
android:title="@string/navigation_item_without_icon"/>
</group>
</menu>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<style name="Theme.Navigation" parent="Theme.Navigation.Base">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
</resources>

View File

@@ -18,12 +18,29 @@
<string name="activity_sample_code">Support Design Demos</string>
<string name="design_fab">Floating Action Button/Basic</string>
<string name="design_navigation">NavigationView/Usage</string>
<string name="design_tabs_basic">TabLayout/Usage</string>
<string name="design_text_input">Text Input</string>
<string name="fab_size_normal">Normal size</string>
<string name="fab_size_mini">Mini size</string>
<string name="navigation_open">Open</string>
<string name="navigation_close">Close</string>
<string name="navigation_item_with_icon">Item with icon</string>
<string name="navigation_item_without_icon">Item without icon</string>
<string name="navigation_message">Clicked: \"%s\"</string>
<string name="navigation_header">Header</string>
<string name="navigation_item_1">Item 1</string>
<string name="navigation_item_2">Item 2</string>
<string name="navigation_item_3">Item 3</string>
<string name="navigation_item_4">Item 4 (disabled)</string>
<string name="navigation_1">1</string>
<string name="navigation_invisible">Invisible</string>
<string name="navigation_subheader">Subheader</string>
<string name="navigation_sub_item_1">Subitem 1</string>
<string name="navigation_sub_item_2">Subitem 2</string>
<string name="tabs_fixed">Fixed</string>
<string name="tabs_scrollable">Scrollable</string>
<string name="tabs_gravity_center">Center</string>

View File

@@ -30,4 +30,17 @@
<item name="colorAccent">#ff0000</item>
</style>
<style name="Theme.Navigation.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#607D8B</item>
<item name="colorPrimaryDark">#455A64</item>
<item name="colorAccent">#FFAB40</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">false</item>
</style>
<style name="Theme.Navigation" parent="Theme.Navigation.Base"/>
</resources>

View File

@@ -0,0 +1,132 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.support.design.widget;
import com.example.android.support.design.R;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
/**
* This demonstrates basic usage of NavigationView
*/
public class NavigationViewUsage extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
private TextView mTextMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.design_navigation);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mTextMessage = (TextView) findViewById(R.id.message);
// Set the color of status bar
TypedValue value = new TypedValue();
getTheme().resolveAttribute(R.attr.colorPrimaryDark, value, true);
mDrawerLayout.setStatusBarBackgroundColor(value.data);
// Retrieve the Toolbar from our content view, and set it as the action bar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Toggle icon
toolbar.setNavigationIcon(R.drawable.ic_action_navigation_menu);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mDrawerLayout.openDrawer(GravityCompat.START);
}
});
// Menu
NavigationView navigation = (NavigationView) findViewById(R.id.navigation);
getMenuInflater().inflate(R.menu.navigation, navigation.getMenu());
navigation.setNavigationItemSelectedListener(mNavigationItemSelectedListener);
navigation.inflateHeaderView(R.layout.design_navigation_header);
}
private NavigationView.OnNavigationItemSelectedListener mNavigationItemSelectedListener
= new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
if (handleNavigationItemSelected(item)) {
mDrawerLayout.closeDrawers();
return true;
}
return false;
}
};
private boolean handleNavigationItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_item_1:
mTextMessage.setText("1");
item.setChecked(true);
return true;
case R.id.navigation_item_2:
mTextMessage.setText("2");
item.setChecked(true);
return true;
case R.id.navigation_item_3:
mTextMessage.setText("3");
item.setChecked(true);
return true;
case R.id.navigation_sub_item_1:
showToast(R.string.navigation_sub_item_1);
return true;
case R.id.navigation_sub_item_2:
showToast(R.string.navigation_sub_item_2);
return true;
case R.id.navigation_with_icon:
showToast(R.string.navigation_item_with_icon);
return true;
case R.id.navigation_without_icon:
showToast(R.string.navigation_item_without_icon);
return true;
default:
return false;
}
}
private void showToast(int res) {
Toast.makeText(this, getString(R.string.navigation_message, getString(res)),
Toast.LENGTH_SHORT).show();
}
@Override
public void onBackPressed() {
if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
}