diff options
author | Chris Banes <chrisbanes@google.com> | 2015-02-16 15:09:20 +0000 |
---|---|---|
committer | Chris Banes <chrisbanes@google.com> | 2015-04-17 15:41:43 +0100 |
commit | 8e7ff4c3f20f8a167f1ce534b767714119f263eb (patch) | |
tree | 28c6ed3aedf67542b6fdb0823d008b7c54235058 /samples/Support7Demos | |
parent | 07dd2eb7e686ed87fc047094bf5fe42578459b18 (diff) | |
download | android_development-8e7ff4c3f20f8a167f1ce534b767714119f263eb.tar.gz android_development-8e7ff4c3f20f8a167f1ce534b767714119f263eb.tar.bz2 android_development-8e7ff4c3f20f8a167f1ce534b767714119f263eb.zip |
Tinted icons sample
Change-Id: If8d456b2cb4c24a7548eae6d29a1e49ee662988e
Diffstat (limited to 'samples/Support7Demos')
-rw-r--r-- | samples/Support7Demos/AndroidManifest.xml | 18 | ||||
-rw-r--r-- | samples/Support7Demos/res/drawable-hdpi/ic_edit.png | bin | 0 -> 202 bytes | |||
-rw-r--r-- | samples/Support7Demos/res/layout/toolbar_tint_icons.xml | 55 | ||||
-rw-r--r-- | samples/Support7Demos/res/menu/actions_tint.xml | 32 | ||||
-rw-r--r-- | samples/Support7Demos/res/values/strings.xml | 7 | ||||
-rw-r--r-- | samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarTintIcons.java | 55 | ||||
-rw-r--r-- | samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarTintIcons.java | 75 |
7 files changed, 242 insertions, 0 deletions
diff --git a/samples/Support7Demos/AndroidManifest.xml b/samples/Support7Demos/AndroidManifest.xml index 26f2a5778..7860462ca 100644 --- a/samples/Support7Demos/AndroidManifest.xml +++ b/samples/Support7Demos/AndroidManifest.xml @@ -176,6 +176,15 @@ </intent-filter> </activity> + <activity android:name=".app.ActionBarTintIcons" + android:label="@string/action_bar_tint_icons" + android:theme="@style/Theme.AppCompat.Light"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.example.android.supportv7.SAMPLE_CODE" /> + </intent-filter> + </activity> + <activity android:name=".app.ActionBarSettingsActionProviderActivity" android:label="@string/action_bar_settings_action_provider" android:theme="@style/Theme.AppCompat.Light.DarkActionBar"> @@ -298,6 +307,15 @@ </intent-filter> </activity> + <activity android:name=".app.ToolbarTintIcons" + android:label="@string/toolbar_icon_tint" + android:theme="@style/Theme.AppCompat.Light.NoActionBar"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.example.android.supportv7.SAMPLE_CODE" /> + </intent-filter> + </activity> + <activity android:name=".app.DialogUsage" android:label="@string/dialog_usage" android:theme="@style/Theme.AppCompat.Light"> diff --git a/samples/Support7Demos/res/drawable-hdpi/ic_edit.png b/samples/Support7Demos/res/drawable-hdpi/ic_edit.png Binary files differnew file mode 100644 index 000000000..b900af02c --- /dev/null +++ b/samples/Support7Demos/res/drawable-hdpi/ic_edit.png diff --git a/samples/Support7Demos/res/layout/toolbar_tint_icons.xml b/samples/Support7Demos/res/layout/toolbar_tint_icons.xml new file mode 100644 index 000000000..ee30e063b --- /dev/null +++ b/samples/Support7Demos/res/layout/toolbar_tint_icons.xml @@ -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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + 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:background="?attr/colorPrimary" + app:navigationTint="#FF0000" + app:overflowTint="#0000FF"/> + + <Button + android:id="@+id/btn_tint_navigation" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/tint_navigation"/> + + <Button + android:id="@+id/btn_tint_navigation_clear" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/tint_navigation_clear"/> + + <Button + android:id="@+id/btn_tint_overflow" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/tint_overflow"/> + + <Button + android:id="@+id/btn_tint_overflow_clear" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/tint_overflow_clear"/> + +</LinearLayout>
\ No newline at end of file diff --git a/samples/Support7Demos/res/menu/actions_tint.xml b/samples/Support7Demos/res/menu/actions_tint.xml new file mode 100644 index 000000000..b218697fe --- /dev/null +++ b/samples/Support7Demos/res/menu/actions_tint.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2015 Google Inc. + + 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" + xmlns:app="http://schemas.android.com/apk/res-auto"> + <item android:id="@+id/action_search" + android:title="@string/action_bar_search" + android:icon="@drawable/abc_ic_search_api_mtrl_alpha" + app:showAsAction="always" + app:iconTint="#FF0000"/> + + <item android:id="@+id/action_edit" + android:title="@string/action_bar_edit" + android:icon="@drawable/ic_edit" + app:showAsAction="always"/> + + <item android:id="@+id/action_force_overflow" + android:title="@string/dummy" + app:showAsAction="never"/> +</menu> diff --git a/samples/Support7Demos/res/values/strings.xml b/samples/Support7Demos/res/values/strings.xml index 6e2c2f756..b1f6ffa52 100644 --- a/samples/Support7Demos/res/values/strings.xml +++ b/samples/Support7Demos/res/values/strings.xml @@ -62,6 +62,7 @@ <string name="appcompat_widgets_buttons">AppCompat/Widgets/Buttons</string> <string name="appcompat_widgets_spinners">AppCompat/Widgets/Spinners</string> <string name="appcompat_widgets_text_input">AppCompat/Widgets/Text Input</string> + <string name="action_bar_tint_icons">AppCompat/Action Bar/Tinted Icons</string> <string name="action_bar_search">Search</string> <string name="action_bar_add">Add</string> @@ -132,6 +133,7 @@ <string name="toolbar_display_options">AppCompat/Toolbar/Toolbar Display Options</string> <string name="toolbar_fragment_pager">AppCompat/Toolbar/Toolbar Fragment ViewPager</string> <string name="toolbar_action_mode">AppCompat/Toolbar/Action Mode</string> + <string name="toolbar_icon_tint">AppCompat/Toolbar/Tinted Icons</string> <string name="dialog_usage">AppCompat/Dialog/Dialog Usage</string> <string name="dialog_title">My great dialog</string> @@ -178,5 +180,10 @@ <string name="sorted_list_activity">Sorted List</string> <string name="add_new_item">Add New Item</string> <string name="start_action_mode">Start Action Mode</string> + <string name="tint_navigation">Tint navigation button</string> + <string name="tint_navigation_clear">Clear navigation button tint</string> + <string name="tint_overflow">Tint overflow button</string> + <string name="tint_overflow_clear">Clear overflow button tint</string> + <string name="dummy">Dummy item</string> </resources> diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarTintIcons.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarTintIcons.java new file mode 100644 index 000000000..b8d647298 --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarTintIcons.java @@ -0,0 +1,55 @@ +/* + * 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.supportv7.app; + +import com.example.android.supportv7.R; + +import android.content.res.ColorStateList; +import android.graphics.Color; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.support.v4.view.MenuItemCompat; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.SearchView; +import android.text.TextUtils; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.widget.TextView; +import android.widget.Toast; + +/** + * This demonstrates the use of tinted menu items, both via menu resources and dynamically via + * MenuItemCompat. + */ +public class ActionBarTintIcons extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.actions_tint, menu); + + MenuItem item = menu.findItem(R.id.action_edit); + MenuItemCompat.setIconTintList(item, ColorStateList.valueOf(Color.GREEN)); + + return true; + } +} diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarTintIcons.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarTintIcons.java new file mode 100644 index 000000000..150cbd5d2 --- /dev/null +++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ToolbarTintIcons.java @@ -0,0 +1,75 @@ +/* + * 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.supportv7.app; + +import com.example.android.supportv7.R; + +import android.content.res.ColorStateList; +import android.graphics.Color; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.Menu; +import android.view.View; + +/** + * This demonstrates the use of tinted navigation and overflow items. + */ +public class ToolbarTintIcons extends AppCompatActivity implements View.OnClickListener { + + private Toolbar mToolbar; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.toolbar_tint_icons); + + mToolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(mToolbar); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + findViewById(R.id.btn_tint_navigation).setOnClickListener(this); + findViewById(R.id.btn_tint_navigation_clear).setOnClickListener(this); + findViewById(R.id.btn_tint_overflow).setOnClickListener(this); + findViewById(R.id.btn_tint_overflow_clear).setOnClickListener(this); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.actions_tint, menu); + return true; + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.btn_tint_navigation: + mToolbar.setNavigationTintList(ColorStateList.valueOf(Color.BLUE)); + break; + case R.id.btn_tint_navigation_clear: + mToolbar.setNavigationTintList(null); + break; + case R.id.btn_tint_overflow: + mToolbar.setOverflowTintList(ColorStateList.valueOf(Color.RED)); + break; + case R.id.btn_tint_overflow_clear: + mToolbar.setOverflowTintList(null); + break; + } + } +} |