Android autoSize cuts off text in TextView bottom line - android

I have such textview in my layout:
<com.google.android.material.textview.MaterialTextView
android:id="#+id/text_body"
style="#style/TvFontSize"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:justificationMode="inter_word"
android:textColor="#color/gray_color"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/text_header" />
with such style:
<style name="TvFontSize">
<item name="android:autoSizeMaxTextSize">100sp</item>
<item name="android:autoSizeMinTextSize">16sp</item>
<item name="android:autoSizeStepGranularity">2sp</item>
<item name="android:autoSizeTextType">uniform</item>
</style>
and long text is cut off as can see:
full layout is below:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:scrollbars="none">
<androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/bottom_nav_color"
tools:context=".pollsModule.IntroFinalFragment">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/toolbarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:subtitleTextAppearance="#style/Toolbar.SubtitleText"
app:titleTextAppearance="#style/Toolbar.TitleText">
<TextView
android:id="#+id/polls_title"
style="#android:style/TextAppearance.Holo.Widget.ActionBar.Title.Inverse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:textAlignment="center" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<View
android:id="#+id/divider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="3dp"
android:background="#color/polls_color"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/toolbarContainer" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/text_header"
style="#style/TvFontSize"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_margin="10dp"
android:textAlignment="center"
android:textColor="#color/gray_color"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/divider" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/text_body"
style="#style/TvFontSize"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:inputType="textMultiLine"
android:justificationMode="inter_word"
android:singleLine="false"
android:text="dfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjddfjjnfdjnfdjndfjnfdjfjdnjnfdjndfdfjfdjnfnjd"
android:textColor="#color/gray_color"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/text_header" />
<com.google.android.material.button.MaterialButton
android:id="#+id/next_text"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:layout_marginTop="10dp"
android:maxLines="1"
android:textAllCaps="false"
android:textColor="#color/white"
app:autoSizeMaxTextSize="16sp"
app:autoSizeMinTextSize="6sp"
app:autoSizeStepGranularity="2sp"
app:autoSizeTextType="uniform"
app:backgroundTint="#color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_body" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</layout>
I can't imagine how to fix it. I tried to use:
android:inputType="textMultiLine"
android:singleLine="false"
but it didn't help me :(

This attribute affects your TextView. Just remove this attribute from your style part.
<item name="android:autoSizeTextType">uniform</item>
For enabling autoSizeTextType. You have to make your textView height Hardcore means in fixed size like android:layout_height="300dp" or match parent.
I hope it helps.
Thank you #Andrew for your clarification.

your TextView should probably have height set to wrap_content instead of 0dp...
android:layout_height="wrap_content"

Related

ShapeableImageView has black background out of rounded

I have ShapeableImageView, and I set corner size. Applying rounded is successful but, In out of rounded It shows black background.
Can you tell me What's the problem?
I searched about it, someone say it's just preview. But It's showing when I run app too.
Like this. I wanna remove the black one.
My layout Xml.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
>
<ImageButton
android:id="#+id/btnPinAddNewEventFolder"
android:layout_width="168dp"
android:layout_height="168dp"
android:background="#drawable/radius_add_pin_folder"
android:elevation="2dp"
android:scaleType="centerCrop"
android:src="#drawable/btn_add_pin_folder"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/clPinEventDefaultFolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
>
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/pinEventDefaultFolderThumbnail"
android:layout_width="168dp"
android:layout_height="168dp"
android:src="#color/gray6"
android:scaleType="centerCrop"
app:shapeAppearanceOverlay="#style/RoundPinFolder"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<ImageView
android:id="#+id/ImgEventDefaultFolderNull"
android:layout_width="69dp"
android:layout_height="65dp"
android:background="#drawable/ic_folder"
android:backgroundTint="#color/gray5"
app:layout_constraintBottom_toBottomOf="#+id/pinEventDefaultFolderThumbnail"
app:layout_constraintEnd_toEndOf="#+id/pinEventDefaultFolderThumbnail"
app:layout_constraintStart_toStartOf="#+id/pinEventDefaultFolderThumbnail"
app:layout_constraintTop_toTopOf="#+id/pinEventDefaultFolderThumbnail" />
<TextView
android:id="#+id/txtDefaultEventPinFolder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:fontFamily="#font/nanumsquare_b"
android:text="이벤트 기본 폴더"
android:textAlignment="textStart"
android:textColor="#color/black"
android:textSize="12sp"
app:layout_constraintEnd_toStartOf="#+id/tvDefaultFolderPinNum"
app:layout_constraintStart_toStartOf="#+id/pinEventDefaultFolderThumbnail"
app:layout_constraintTop_toBottomOf="#+id/pinEventDefaultFolderThumbnail"
/>
<TextView
android:id="#+id/tvDefaultEventFolderPinNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="#font/nanumsquare_b"
android:text="num"
android:textAlignment="textEnd"
android:textColor="#color/gray3"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="#+id/pinEventDefaultFolderThumbnail"
app:layout_constraintTop_toBottomOf="#+id/pinEventDefaultFolderThumbnail" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="24dp"
app:layout_constraintTop_toBottomOf="#+id/constraintLayout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:orientation="vertical"
>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvEventPinFolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
style code
<style name="RoundPinFolder">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">10%</item>
</style>
Use padding inside ShapeableImageView like
android:padding="0.5dp"
Example
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/imgBanner"
android:layout_width="0dp"
app:shapeAppearanceOverlay="#style/roundedImageViewRounded"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:padding="0.5dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
In your manifest file, in the application tag. set
android:hardwareAccelerated="true"
By default it is false

Bottom of one layout in the middle of another layout vertically in android xml?

I want to create the below layout, but not sure how to do it.
height of both blue layout and white layout is set to "wrap_content" and therefor they don't have a constant height.
The point is, I want the bottom of blue layout to always be in the middle of white layout(vertically). I have no idea how to do it using constraint or relative layout.
I searched but couldn't find any solution to this problem.
modify this accordingly
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/credentials_card"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="20dp"
android:padding="#dimen/spacing_mlarge"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/image_logo">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_medium"
android:visibility="visible"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="6dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true"
tools:ignore="MissingConstraints">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="#dimen/spacing_xmlarge">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="25dp"
android:fontFamily="#string/font_family_light"
android:text="L O G I N"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Large"
android:textColor="#color/colorPrimary"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MOBILE"
android:textAlignment="center"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Caption"
android:textColor="#color/colorPrimary" />
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/mobileNumberET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:maxLength="10"
android:maxLines="1"
android:singleLine="true"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Large"
android:textColor="#color/colorPrimary"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="PASSWORD"
android:textAlignment="center"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Caption"
android:textColor="#color/colorPrimary" />
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/passwordET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:maxLength="50"
android:maxLines="1"
android:singleLine="true"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Large"
android:textColor="#color/colorPrimary"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="#+id/loginButton"
android:layout_width="match_parent"
android:layout_height="57dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="#drawable/button_round"
android:text="L O G I N"
android:fontFamily="#string/font_family_light"
android:textAllCaps="false"
android:textColor="#android:color/white"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="#+id/credentials_card"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
You can try this (I don't include border radius so take care of it..)
<androidx.constraintlayout.widget.ConstraintLayout 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#8F2A2A"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:layout_marginTop="200dp"
android:background="#B8C159"
app:layout_constraintTop_toTopOf="#+id/constraintLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here My Ans check
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="#dimen/dp_16"
android:layout_marginRight="#dimen/dp_16"
app:cardBackgroundColor="#color/blue"
app:cardCornerRadius="#dimen/dp_10"
app:cardElevation="#dimen/dp_5"
app:cardUseCompatPadding="true"
android:id="#+id/card_container"
app:layout_constraintBottom_toBottomOf="#id/guideline"
app:layout_constraintTop_toTopOf="parent">
</androidx.cardview.widget.CardView>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.42" />
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="100dp"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="#dimen/dp_10"
app:cardElevation="#dimen/dp_5"
app:cardUseCompatPadding="true"
android:layout_marginStart="#dimen/dp_20"
android:layout_marginEnd="#dimen/dp_20"
app:layout_constraintStart_toStartOf="#id/card_container"
app:layout_constraintEnd_toEndOf="#id/card_container"
app:layout_constraintTop_toTopOf="#id/guideline"
app:layout_constraintBottom_toTopOf="#id/guideline">
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
Use constraint layout as parent and then constraint the topOfSmallComponent to the bottomOfBigComponent. Then again constraint the bottomOfSmallComponent to the bottomOf BigComponent.
Example code below:
app:layout_constraintTop_toBottomOf="your_blue_items_id"
app:layout_constraintBottom_toBottomOf="your_blue_items_id"

Android - Scale Image to status bar of the phone

Simply, I have a linear layout that separates the screen to 2 pieces from middle and in the first piece I have a constraint layout that contains mountain.png .Because of i set NoActionBar and white for statusBarColor in Themes.xml, as a result above the image there is area that seems white.So I want to remove the white area and scale the image through status bar of the phone.
I tried to remove status bar, it didn't work.
I tried to add android:fitsSystemWindows="true" attribute to .XML file and it didn't work too.
My .xml file
<androidx.constraintlayout.widget.ConstraintLayout 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=".ui.sign_in.telephone.PhoneNumberFragment"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#drawable/mountain">
<TextView
android:id="#+id/baslaText"
android:layout_width="match_parent"
android:gravity="center"
android:layout_marginTop="100dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="100dp"
android:layout_marginRight="100dp"
android:layout_height="wrap_content"
android:textSize="38sp"
android:textColor="#color/white"
android:text="Başlayın" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/baslaText"
android:layout_marginTop="20dp"
android:textColor="#color/white"
android:textSize="16sp"
android:text="Taşımaya başlamak için kaydolun, ilk \n olarak telefon numaranızı girin"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.cardview.widget.CardView
android:elevation="4dp"
app:cardCornerRadius="14dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/telephoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:text="Telefon numaranızı giriniz"
android:textColor="#color/black"
android:textSize="28sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="match_parent"
android:gravity="center"
android:id="#+id/telephoneText"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:textSize="18sp"
app:layout_constraintRight_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/telephoneNumber"
android:text="Taşımaya başlamak için kaydolun, ilk \n olarak telefon numaranızı girin"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/telephoneTag"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="40dp"
android:text="Telefon Numarası"
android:textColor="#color/black"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#id/telephoneText" />
<com.google.android.material.textfield.TextInputLayout
android:elevation="2dp"
app:cardCornerRadius="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/telephoneNumberInput"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/telephoneTag"
android:layout_marginTop="20dp"
app:errorEnabled="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/telephoneNumberEditText"
android:layout_width="match_parent"
android:background="#android:color/transparent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:inputType="number"
android:hint="+.. ... ... .. .."
android:maxLength="12"
android:textColor="#color/black"
android:textSize="14sp"
/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginLeft="30dp"
android:layout_marginBottom="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="10dp"
android:background="#color/purple_500"
android:backgroundTint="#color/purple_500"
android:text="Başlayın"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/telephoneNumberInput" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
My themes.xml file.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.UI" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/teal_200</item>
<item name="colorPrimaryVariant">#color/white</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
write this on your activity onCreate:
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
getWindow().setStatusBarColor(Color.TRANSPARENT);
This code piece did the job I desired.

androidx.appcompat.widget.SearchView doesn't show up in toolbar

I'm working on a personal Android application. In this application, there is a single main Activity with two Fragments. In one of them, I want to implement the Algolia InstantSearch according to this guide.
This is my fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false">
<androidx.appcompat.widget.SearchView
android:id="#+id/searchView"
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:iconifiedByDefault="false"
tools:queryHint="Hello"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
<TextView
android:id="#+id/stats"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="16dp"
android:textAppearance="#style/TextAppearance.MaterialComponents.Caption"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/memory_recyclerview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#+id/toolbar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="#+id/stats">
</androidx.recyclerview.widget.RecyclerView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:padding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="#+id/stats">
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/add_memory_fab_menu"
android:layout_width="297dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:clickable="true"
app:menu_animationDelayPerItem="50"
app:menu_backgroundColor="#android:color/transparent"
app:menu_buttonSpacing="0dp"
app:menu_colorNormal="#color/babyBlue"
app:menu_colorPressed="#color/red"
app:menu_colorRipple="#99FFFFFF"
app:menu_fab_hide_animation="#anim/fab_slide_out_to_right"
app:menu_fab_show_animation="#anim/fab_slide_in_from_right"
app:menu_fab_size="normal"
app:menu_icon="#drawable/ic_add_white_24dp"
app:menu_labels_colorNormal="#333333"
app:menu_labels_colorPressed="#444444"
app:menu_labels_colorRipple="#66FFFFFF"
app:menu_labels_cornerRadius="3dp"
app:menu_labels_ellipsize="none"
app:menu_labels_hideAnimation="#anim/fab_slide_out_to_right"
app:menu_labels_margin="0dp"
app:menu_labels_maxLines="-1"
app:menu_labels_padding="8dp"
app:menu_labels_paddingBottom="4dp"
app:menu_labels_paddingLeft="8dp"
app:menu_labels_paddingRight="8dp"
app:menu_labels_paddingTop="4dp"
app:menu_labels_position="left"
app:menu_labels_showAnimation="#anim/fab_slide_in_from_right"
app:menu_labels_showShadow="true"
app:menu_labels_singleLine="false"
app:menu_labels_textColor="#FFFFFF"
app:menu_labels_textSize="14sp"
app:menu_openDirection="up"
app:menu_shadowColor="#66000000"
app:menu_shadowRadius="4dp"
app:menu_shadowXOffset="1dp"
app:menu_shadowYOffset="3dp">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/add_memory_fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_insert_comment_white_24dp"
app:fab_label="Create Memory"
app:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/add_memory_fab_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_search_white_24dp"
app:fab_label="Search"
app:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/add_memory_fab_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_logout_new_white_24dp"
app:fab_label="Logout"
app:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
The problem is the androidx.appcompat.widget.SearchView doesn't appear in the toolbar. Instead, the toolbar still with empty space.
How can I fix this? Feel free to ask for additional information.
You forget change width and height
Use this code
<androidx.appcompat.widget.SearchView
android:id="#+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:iconifiedByDefault="false"
tools:queryHint="Hello"/>
Or if you want automatically fill parent when use ConstraintLayout you miss below line
app:layout_constraintEnd_toEndOf="parent"
So you can use this code too
<androidx.appcompat.widget.SearchView
android:id="#+id/searchView"
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:iconifiedByDefault="false"
tools:queryHint="Hello"/>

Why doesn't Linear Layout maxHeight work?

This is my layout.
I set max and min height on the linear layout but max height seems not to be working. In fact if TextView R.id.testo has a lot of text this won't be trimmed. This doesn't happen if I set fixed height. But I didn't want to set a fixed height in order to make it correctly resizable when for instance spilt screen mode is selected.
<androidx.constraintlayout.widget.ConstraintLayout 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=".WidgetSettingsActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/transparent"
android:elevation="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="?attr/popupThemeToolbar"
app:title=""
app:titleTextAppearance="#style/ToolbarTitle" />
<LinearLayout
android:id="#+id/card"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="55dp"
android:layout_marginTop="#dimen/margin_16"
android:layout_marginEnd="55dp"
android:background="#drawable/widget_background"
android:clickable="false"
android:maxHeight="400dp"
android:minHeight="400dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/titolo"
style="#style/Base.TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:drawableEnd="#drawable/ic_if_settings_1540178"
android:ellipsize="end"
android:fontFamily="#font/encodesanscondensed_medium"
android:hint="#string/no_title"
android:maxLines="1"
android:padding="8dp"
android:textSize="18sp"
tools:text="Title" />
<LinearLayout 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:orientation="vertical"
android:paddingStart="#dimen/fab_margin"
android:paddingTop="4dp"
android:paddingEnd="#dimen/fab_margin"
android:paddingBottom="4dp">
<TextView
android:id="#+id/testo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/encodesanscondensed_regular"
android:hint="#string/no_text"
android:textColor="?android:attr/editTextColor"
android:textSize="18sp"
tools:text="Text multiple rows" />
<TextView
android:id="#+id/last_modified"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginTop="24dp"
android:fontFamily="#font/encodesanscondensed_regular"
android:gravity="end|bottom"
android:textSize="12sp"
tools:text="#string/last_modified_s" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="35dp"
android:layout_marginEnd="35dp"
android:layout_marginBottom="8dp"
android:gravity="bottom"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/card"
app:layout_constraintVertical_bias="0.905">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="13dp"
android:layout_marginBottom="#dimen/margin_16"
android:fontFamily="#font/encodesanscondensed_medium"
android:text="#string/background_transparency"
android:textAllCaps="true"
android:textColor="#color/colorPrimary"
android:textSize="13sp" />
<androidx.appcompat.widget.AppCompatSeekBar
android:id="#+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255"
android:min="0"
android:progressBackgroundTint="#color/white_opacity" />
</LinearLayout>
As your parent view is ConstraintLayout.
I have also implemented the max and min and for me
Replace these lines
android:maxHeight="400dp"
android:minHeight="400dp"
with
app:layout_constraintHeight_max="400dp"
app:layout_constraintHeight_min="400dp"
app:layout_constrainedHeight="true"
This code working fine. I hope it also works for you.
You have used for your LinearLayout within Constraint layout
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
End_toEndOf set to parent
Start_toStartOf is set to parent
And thats the reason maxHeight is not working.

Categories

Resources