Searchview in LinearLayout using android.support.v7.widget.SearchView - android

I need a SearchView inside a LinearLayout and I have to support API level 7 and higher. Is it possible to use the support-v7 libraries for this? All the questions in here are about using the support-v7 searchview widget in the actionbar. Does anyone know how to use it in the layout? Thanks.

<?xml version="1.0" encoding="utf-8"?>
<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.support.v7.widget.SearchView
android:id="#+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:queryHint="#string/search_hint"
app:iconifiedByDefault="false" />
</LinearLayout>

Related

Unable to see any icons at the Bottom Navigation bar

I have been trying to display the icon images on my bottom navigation bar. No matter what I try I still can't get it. I have been trying so many different ways to solve but to no avail. Could someone please help me on this? Maybe I have missed out on something.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/yellow"
tools:context=".MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#+id/fragment_layout">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavView"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_gravity="bottom"
android:background="#color/white"
app:menu="#menu/menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>```
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/nav_donate"
android:icon="#drawable/donate_icon"
android:title="Donate"/>
<item
android:id="#+id/nav_status"
android:icon="#drawable/status_icon"
android:title="Status"/>
<item
android:id="#+id/nav_history"
android:icon="#drawable/history_icon"
android:title="History"/>
<item
android:id="#+id/nav_logout"
android:icon="#drawable/logout_icon"
android:title="Log Out"/>
</menu>
```
The image link below is how the display is as of now.
[1]: https://i.stack.imgur.com/EH6AQ.png
Your layout height is set to 0dp
android:layout_height="0dp" where it is matching the constraints it is given. I have not seen your display but I'm guessing the frame layout is hiding your bottomNavView.
Change it to
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#+id/fragment_layout"
app:layout_constraintTop_toTopOf="parent">
app:layout_constraintBottom_toTopOf="#id/bottomNavView">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavView"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_gravity="bottom"
android:background="#color/white"
app:layout_constraintBottom_toBottomOf="parent">
app:menu="#menu/menu"/>
EDIT
With help from #Niaj Mahmud .
Change the material version in your app level build.gradle files from 1.5.0 to 1.3.0
yes in physical device it's work properly but in preview it does not show. this issue is for material version 1.5.0 .. try material 1.3.0 version
live view of bottom navigation in design view is not showing icons and the menu resource

Material Search Bar isn't showing in the layout preview

Good Morning
Just want to ask why the layout of my Material Search bar now showing in the layout here is my code
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ProductView">
<com.mancj.materialsearchbar.MaterialSearchBar
style="#style/MaterialSearchBarDark"
app:mt_speechMode="true"
app:mt_hint="Custom hint"
app:mt_maxSuggestionsCount="10"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/searchBar" />
</RelativeLayout>
Here are the screenshots of what the layout looks like:
Its because the third party library used element which is may not present in your project.
In your case it should be constraintlayout
I just added
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
and the view is visible for me. But its not necessary for your project if you are not using it in other areas.

Android studio different timepicker

How can I get this timpicker
Instead of this one?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TimePicker
android:id="#+id/timepicker_arbetstid"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
I think you can try
android:calendarViewShown="false"
and
android:timePickerMode="spinner"
in the datepicker xml.
For backwards compatibility, you may use this library to support material design time picker:
https://github.com/code-troopers/android-betterpickers

Does android:theme in appcompat 22.1.0 only work for Toolbar?

In the following layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
TextView is not using themed text colors on pre-L devices. If I move this theme declaration to TextView it works on all devices. Chris Banes in his article wrote:
In 22.1.0 we now have expanded that functionality so that you can set
a theme on any view in your layouts.
https://chris.banes.me/2015/04/22/support-libraries-v22-1-0/
So I'm confused, bug?
EDIT:
I looked into Toolbar and Toolbar also seems to have this issue—the following layout doesn't work as intended too:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<TextView
android:layout_width="wrap_content"
android:text="####SDAG"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
I've found source of the problem. I was directly adding items to R.id.content. Like LayoutInflater.from(this).inflate(R.layout.my_activity, findViewById(R.id.content); instead of using setContentView method that does all the magic stuff. Unfortunately in documentation there is no word that you must use setContentXXX method.
With new version (v22.1) of support lib your activity should extend AppCompatActivity instead of ActionBarActivity you used to extend so far.
Here's Google devs' post: http://android-developers.blogspot.com/2015/04/android-support-library-221.html

Adding shadow below TabBar - Material Design

I have an actionbar and tab bar. I removed shadow below actionbar with
<item name="android:windowContentOverlay">#null</item>
Though, I want to add shadow under tab bar. I'm using SlidingTabLayout. My tab TextView:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabText"
android:layout_width="wrap_content"
android:layout_height="#dimen/actionbar_height"
android:textColor="#color/tab_color"
android:gravity="center"
android:textAllCaps="true"
android:singleLine="true" />
How to do that?
jmols answer results in a different shadow than what Google apps (e.g. Play Newsstand) use. This is my method, which results in the shadow looking exactly the same as Play Newsstand:
Create a drawable called shadow.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#android:color/transparent"
android:endColor="#33000000"
android:angle="90">
</gradient>
</shape>
Then, set that shadow to your content layout, for example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Your views here -->
<View
android:layout_width="match_parent"
android:layout_height="8dp"
android:background="#drawable/shadow" />
</RelativeLayout>
Placed underneath your toolbar/action bar, this will look exactly the same as the implementation in Play Newsstand and Play Store.
Shadows are currently only supported on Api level 21 (as they are rendered in real time) and are not provided by the support library unfortunately.
Hence you will have to mimic the shadows yourself using a custom drawable on api levels < 21.
The easiest way to do this is:
take the shadow 9-patch from the Google IO app.
set that shadow to your main content layout, for example:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Toolbar
android:id="#+id/tb_toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/abc_action_bar_default_height_material"
android:title="#string/toolbar_title"
android:elevation="#dimen/toolbar_elevation"/>
<FrameLayout
android:id="#+id/fl_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/tb_toolbar"
android:foreground="#drawable/bottom_shadow"/>
</RelativeLayout>
Note: the only notable exception to this is CardView, this one does cast its own shadow on older api levels.
Have a look at this post for more information.
If you are using Android Material Design, to add a shadow to a view you need to specify the android:elevation attribute in your layout or call myView.setElevation() method in your code. You can have more on defining shadows with material design in the android documentation
Just add elevation to your Tablayout (0dp - 25dp). Read the material design guidelines for more information about elevation.
android:elevation="10dp"
Below example:
<android.support.v7.widget.Toolbar xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="#color/splashGreenTop"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:elevation="10dp" />
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_below="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:elevation="10dp"/>
Same question: Link
be aware, if you have the following line in the manifest then shadows wont show:
android:hardwareAccelerated="false"
And another link to follow: Link

Categories

Resources