I want a customised progress bar in android, like this:
I want progress bar same as it is, but unable to achieve this.
This will give you the result that you want:
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="100dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginVertical="20dp"
android:layout_marginHorizontal="20dp"
>
<com.google.android.material.progressindicator.LinearProgressIndicator
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:progress="80"
app:indicatorColor="#color/blue_500"
app:trackColor="#color/blue_200"
app:trackThickness="16dp"
app:trackCornerRadius="100dp"
/>
</com.google.android.material.card.MaterialCardView>
app:indicatorColor: This is the color of the indicator, it depends on the value of android:progress
app:trackColor: This is the color of the track, it is the background color of the LinearProgressIndicator
app:trackThickness: This is the thickness of the track, which means that this value is the height of the LinearProgressIndicator
Note: The MaterialCardView should be inside a ViewGroup ( ConstraintLayout, LinearLayout ... ).
Related
I want to make my TextView background color without the drawable on the left like this:
But when I'm trying to do it I got like this:
This is my textview code:
<TextView
android:id="#+id/Typetxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/space0"
android:drawableStart="#drawable/ic_type_icon"
android:drawablePadding="10dp"
android:textColor="#color/black"/>
and in the Adapter this is the code for coloring the background:
holder.Typetxt.setText(posts.getTRADE_TYPE_NAME());
if(posts.getTRADE_TYPE_NAME().equals("VL")){
holder.Typetxt.setTextColor(Color.parseColor("#FF7464"));
holder.Typetxt.setBackgroundResource(R.drawable.vl_background);
holder.cardViewMain.setBackgroundResource(R.color.VLBackground);
The background is set for the entire view- not just the text. If you're using a drawableStart, that includes the drawable. If you don't want that, use 2 views, an ImageView and a TextView.
You can make this layout without using a drawable. Make the cardView's background color, same as the color you want on the left side strip. Add a ConstraintLayout inside it and give this ConstraintLayout white background color and a marginStart of whatever size you want your strip width to be.
<androidx.cardview.widget.CardView
android:id="#+id/cvContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardBackgroundColor="#color/orange"
app:cardCornerRadius="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:layout_marginStart="12dp"
>
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tvText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="Lorem \nipsum \ndolor" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
Result
I have a text view and rating bar align horizontally.Rating bar start after the end of rating bar.
When this text of the text view get too long to fit in the screen it will push rating bar off the screen. In a case like this I want text view to take space in the screen until the point where rating bar touch screen end and show 3 dots in the end of the text view. But if text is short rating bar should start after that.
Please explain a way to achieve this.
I think you must have to explore constraint layout, for now solution of you isssue is here. I hope this may help you.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="wrap_content">
<TextView
android:id="#+id/tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:ellipsize="end"
android:text="sandeep sankla"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/rating_layout"
app:layout_constraintTop_toTopOf="parent" />
<RatingBar
android:id="#+id/rating_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toRightOf="#+id/tv"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
In the following XML, can I reference the width/height of android:attr/progressBarStyle for android:layout_height?
I am showing/hiding a loading circle with a text message. Since ContentLoadingProgress bar does not seem to support adding a text message, I used a TextView along with it.
I used wrap_content for the height/width, but the problem is when calling show() when it has been hidden using hide(), there is a split-second delay when the circle is empty and the width is collapsed. Then the circle appears, and its width is widen, and the text message moves. This looks ugly.
I want to change
android:layout_width="wrap_content"
to something like
android:layout_width="(reference the width of android:attr/progressBarStyle)"
so that it would remain constant.
Layout.xml
<LinearLayout
android:orientation="horizontal"
android:gravity="center"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.ContentLoadingProgressBar
style="?android:attr/progressBarStyle"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<TextView
tools:text="Loading..."
android:textAppearance="#android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
I have set both the CardView's background and FrameLayout's to transparent yet the result is still a white color bg.
Is this some default behavior? What should I change to my xml layout file for having a transparent bg ?
Layout file :
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
card_view:cardBackgroundColor="#android:color/transparent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="#android:color/transparent"
android:layout_width="match_parent"
android:layout_height="140dp"
tools:layout_gravity="center">
<TextView
android:id="#+id/dayID"
android:textColor="#color/link_text_material_light"
android:textSize="26dp"
android:layout_marginLeft="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/monthID"
android:textColor="#color/link_text_material_light"
android:layout_marginLeft="60dp"
android:textSize="26dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/splashID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/link_text_material_light"
android:textSize="26dp"
android:layout_gravity="center"
android:gravity="center"
android:padding="20dp"
tools:text="Hero text" />
<TextView
android:id="#+id/sunbathMinsID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/link_text_material_light"
android:textSize="26dp"
android:layout_gravity="bottom"
android:gravity="center"
android:padding="20dp"
tools:text="Hero text" />
</FrameLayout>
</android.support.v7.widget.CardView>
A transparent background can be obtained for any number of views within your XML.
This is a decent explanation for an imageview.
Set transparent background of an imageview on Android
Cardviews are a lot the same but have a little different attribute and are explained very well with the "app:cardBackgroundColor= "#android:color/transparent""
See this post for that type of attribute.
Transparent background on CardView - Android
Setting your cardView and the subsequent FrameLayout both to transparent will definitely get the job done and make both views transparent. However, the activity will always have a solid background. The Activity only doesn't have a solid background when you set a resource as the background and the views placed within that Activity will show the current background if they are set to transparent as seen in the links above.
Therefore, even though you have set your "views" to transparent, the Activity will always need a color or image to show the in background. Meaning that, yes you will still have a white background behind your cardView, unless you change that color.
i added background color of my layout, as white.
then i created a list by extending BaseAdapter class.
but my list item is not focusable(when i move cursor to any item it do not show focus color).
but if i remove background color tag of layout, it works fine.below is my xml layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:background="#color/color_white">
<ImageView
android:id="#+id/icon"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:visibility="visible" />
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:textColor="#color/color_white"
android:textSize="20dp"
android:visibility="visible" />
</LinearLayout>
please help.
The list item backgrounds are "State List Drawables", which define a color for different states of a view. If you set the background to just a simple color, it will be that color in all instances. You need to only override the specific "state" in the default drawable to keep the rest of the colors intact. Here's an example.