I have different activities in my project with listview in it. I am using app compact v7 and following material design.My requirement is to shown transparent toolbar and statusbar like iOS and when user will scroll the listeview towards up. listview should be visible behind the toolbar and actionbar. Please let me know how can i do this. I tried a lot of solution but could not achieve the desired o/p.
Styles
<item name="colorPrimaryDark">#android:color/transparent</item>
XML Layout
<android.support.v7.widget.Toolbar
android:id="#+id/my_awesome_toolbarAdd"
android:layout_height="56dp"
android:layout_width="match_parent"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="#android:color/transparent" />
You can try this (don't do the optional step #5 in your case):
Unable to make toolbar transparent in Android
Related
I am new to android development and I want to make an app that is almost immersive. Does android let you remove the toolbar and use only the tabs?
Yes, android.support.v7.widget.Toolbar is optional. You can remove it anytime from your layout.
If you don't want to use Toolbar then just use TabLayout in your layout XML:
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#ff4938"/>
Hope this will help~
I am trying to style a SearchView in a toolbar to look / behave like the SearchView in the Google Play Store app. It seems to wrap the searchview in a cardview but it also seems to integrate up button / drawer toggle behavior.
This is the main activity searchView, it has integrated drawer toggle
when you click on it, the drawer toggle changes to arrow (that when clicked will remove focus from the search view)
When you click on an app in the store, you go to app detail page and you have what looks like iconified version of the search view as a collapsed action item with up button:
Finally if you click on search icon it expands as an action item (with a kind of ripple animation) and displays all the way across the screen and incorporates the up button:
When I try to do it myself I have a lot of problems. I tried to wrap the searchview in a cardview and put that in a toolbar. It works but there is always padding on the left side that I can't remove (I tried contentInsetStart, doesn't work):
<android.support.v7.widget.Toolbar
android:id="#+id/activityCatalogToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
android:theme="#style/AppTheme.AppBarOverlay"
app:contentInsetStart="0dp"
app:contentInsetLeft="0dp">
<android.support.v7.widget.CardView
android:id="#+id/activityCatalogSearchContainer"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
app:cardCornerRadius="4dp"
app:cardElevation="8dp">
<android.support.v7.widget.SearchView
android:id="#+id/activityCatalogSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:queryHint=""
android:iconifiedByDefault="false"/>
</android.support.v7.widget.CardView>
</android.support.v7.widget.Toolbar>
I have also tried to remove the toolbar and replace it with just a FrameLayout. This allows me to control the padding but obviously I lose the toolbar functionalities (up button, etc) and also introduces theming problems (icons and text disappear).
Does anyone have an idea how they are doing this? I don't want to add another library just to style widgets that already exist in the framework. Thanks!
You might try to deep dive into this project:
https://android.googlesource.com/platform/packages/apps/Dialer/
For Lollipop or Marshmallow, or N it has a SearchEditTextLayout which is what you need:
Advantage
a code made by Google, not third party.
You have to use this Custom Implementation of SearchView.
https://github.com/Quinny898/PersistentSearch
Android Studio:
Add the Sonatype repository if you have not already:
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
Import it as a dependency:
compile 'com.quinny898.library.persistentsearch:library:1.1.0-SNAPSHOT'
In your layout:
<com.quinny898.library.persistentsearch.SearchBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/searchbox"
/>
Output :
I myself was trying to build this. Ended up just making the search button an ImageButton. a click on this would Trigger a Fragment to be added on top which would contain an Edittext inside an layout made to look like this. and this Fragment consisted of a listview below this searchbox to show suggestions.
Tip: Keep the Fragment's rootlayout without any background and set clickable to true to achieve best results with a transparent pane
I've been trying to customize my Toolbar using the support library. while setting android:theme works perfectly on API21+ , lower APIs seem to completely ignore it.
here's my xml:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" makes the toolbar have White icons in API21+, the icons remain black on older devices.
update: I tested by adding another child (tabLayout) to my appBarLayout. the theme was correctly applied. however the support toolbar completely refuses to recognize the theme even if set directly.
After days of struggling I finally found the problem. my layout was set before calling super.onCreate() and for whatever reason this made Toolbar not apply proper theme in pre-lolipop devices where the native Toolbar is not used.
so I made sure:
setContentView(R.layout.main);
comes after:
super.onCreate(savedinstancestate);
hey your have to make the styles files with the version number .
For that go to the values and right click and then click the Values Resource file
then name the file as styles and then in the dialog under the option available Qualifiers select the version file then press the icon >> and then enter the version 19 on it and this file will work for a version less then Api 21+
this is the dialog you will get on click of value Resource file
this is the final dialog where you need to enter your version number
It might help you.
You have set the theme style in API version based folders and apply, So that it will apply based on the API versions.
put themes inside styles.xml.
then replicate the styles.xml in values folder for different API levels based folder[based on your requirement you have to create value-X folders]
please refer below image.
Click here to view image
I made a navigation icon through the Vector Asset wizard in Android Studio to place in my Toolbar. By default, the color of the image is black. It doesn't give me the option to change it in the wizard. So is there a way to change the color in xml? This is how it is set in my toolbar layout file:
<android.support.v7.widget.Toolbar
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="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
app:navigationIcon="#drawable/nav_menu_icon">
</android.support.v7.widget.Toolbar>
As you can see, the image is set as app:navigationIcon="#drawable/nav_menu_icon". So is it possible to change the icon's color? I tried this solution but it wasn't working for me. The other solutions were given in code but I would like to use an xml version if possible. Also, my app is supporting API 16 and later.
You can change color of "nav_menu_icon".
Need to open nav_menu_icon.xml in studio or any editors and change the attribute "fillColor".
It's android:fillColor="#FF000000" by default.
Even though there's no subtitle in my Toolbar, the title is shifted to top. How can I align it with navigation icon?
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:navigationIcon="#drawable/abc_ic_ab_back_mtrl_am_alpha"
android:gravity="top"
app:title="Hello title"
android:background="#drawable/citylook"/>
You should assing a minHeight to your Toolbar.
<android.support.v7.widget.Toolbar
android:minHeight="?attr/actionBarSize">
I faced a similar issue recently and managed to find the solution. I hope that'll fix yours too. I just paste the link here 'cause I'm lazy: Android Toolbar: title and overflow menus aligment issue on 5.0 only
Basically, if you are launching the application on a Lollipop device, there is no need to set an Activity with no ActionBar and replace it with a Toolbar: you have to code different themes and layouts for pre-Lollipop and Lollipop devices.
Let me now if that works for you as well!