Creating a Preference Screen with support (v21) Toolbar

Please find the GitHub Repo: Here A bit late to the party, but this is my solution that I am using as a work around continuing to use PreferenceActivity: settings_toolbar.xml : <?xml version=”1.0″ encoding=”utf-8″?> <android.support.v7.widget.Toolbar xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/toolbar” app:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:minHeight=”?attr/actionBarSize” app:navigationContentDescription=”@string/abc_action_bar_up_description” android:background=”?attr/colorPrimary” app:navigationIcon=”?attr/homeAsUpIndicator” app:title=”@string/action_settings” /> SettingsActivity.java : public class SettingsActivity extends PreferenceActivity { … Read more

No shadow by default on Toolbar?

I ended up setting my own drop shadow for the toolbar, thought it might helpful for anyone looking for it: <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_gravity=”top” android:orientation=”vertical”> <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:background=”@color/color_alizarin” android:titleTextAppearance=”@color/White” app:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar”/> <FrameLayout android:layout_width=”match_parent” android:layout_height=”match_parent”> <!– **** Place Your Content Here **** –> <View android:layout_width=”match_parent” android:layout_height=”5dp” android:background=”@drawable/toolbar_dropshadow”/> </FrameLayout> </LinearLayout> @drawable/toolbar_dropshadow: <?xml version=”1.0″ encoding=”utf-8″?> … Read more

How to make Toolbar transparent?

Create your toolbar.xml file with background of AppBarLayout is @null <?xml version=”1.0″ encoding=”utf-8″?> <android.support.design.widget.AppBarLayout android:id=”@+id/general_appbar” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:background=”@null” xmlns:android=”http://schemas.android.com/apk/res/android”> <android.support.v7.widget.Toolbar android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize”> <TextView android:layout_width=”match_parent” android:layout_height=”wrap_content” android:gravity=”center_horizontal” android:text=”Login” android:textSize=”20sp”/> </android.support.v7.widget.Toolbar> </android.support.design.widget.AppBarLayout> and here is result:

Display Back Arrow on Toolbar

If you are using an ActionBarActivity then you can tell Android to use the Toolbar as the ActionBar like so: Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar); setSupportActionBar(toolbar); And then calls to getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); will work. You can also use that in Fragments that are attached to ActionBarActivities you can use it like this: ((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); ((ActionBarActivity) … Read more

Creating a button in Android Toolbar

ToolBar with Button Tutorial 1 – Add library compatibility inside build.gradle dependencies { compile fileTree(dir: ‘libs’, include: [‘*.jar’]) compile ‘com.android.support:appcompat-v7:21.0.3’ } 2 – Create a file name color.xml to define the Toolbar colors <?xml version=”1.0″ encoding=”utf-8″?> <resources> <color name=”ColorPrimary”>#FF5722</color> <color name=”ColorPrimaryDark”>#E64A19</color> </resources> 3 – Modify your style.xml file <resources> <!– Base application theme. –> <style … Read more

How to use SearchView in Toolbar Android

You have to use Appcompat library for that. Which is used like below: dashboard.xml <menu xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” xmlns:app=”http://schemas.android.com/apk/res-auto”> <item android:id=”@+id/action_search” android:icon=”@android:drawable/ic_menu_search” app:showAsAction=”always|collapseActionView” app:actionViewClass=”androidx.appcompat.widget.SearchView” android:title=”Search”/> </menu> Activity file (in Java): public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.dashboard, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchManager searchManager = (SearchManager) MainActivity.this.getSystemService(Context.SEARCH_SERVICE); SearchView searchView = null; if (searchItem … Read more

Android transparent status bar and actionbar

I’m developing an app that needs to look similar in all devices with >= API14 when it comes to actionbar and statusbar customization. I’ve finally found a solution and since it took a bit of my time I’ll share it to save some of yours. We start by using an appcompat-21 dependency. Transparent Actionbar: values/styles.xml: … Read more

Android API 21 Toolbar Padding

The left inset is caused by Toolbar’s contentInsetStart which by default is 16dp. Change this to 72dp to align to the keyline. Update for support library v24.0.0: To match the Material Design spec there’s an additional attribute contentInsetStartWithNavigation which by default is 16dp. Change this if you also have a navigation icon.

This Activity already has an action bar supplied by the window decor

I think you’re developing for Android Lollipop, but anyway include this line: <item name=”windowActionBar”>false</item> to your theme declaration inside of your app/src/main/res/values/styles.xml. Also, if you’re using AppCompatActivity support library of version 22.1 or greater, add this line: <item name=”windowNoTitle”>true</item> Your theme declaration may look like this after all these additions: <!– Base application theme. –> … Read more

tech