Dissapearing text when setting a TextView background in Android - android

Both properties are set programmatically. I tried restarting, changing AVD - bu still when TextView background is set - text dissapears. And yes, it has different color then background. Without background text is visible. I don't know where is the problem...
{This code below works fine}
<TextView
android:id="#+id/txt_Number"
android:layout_width="match_parent"
android:layout_height="25dp"
android:gravity="center"
android:text="1"
android:textColor="#color/red"
android:textSize="10sp"
android:textStyle="bold" />
This code below show only background, no text :/
<TextView
android:id="#+id/txt_Number"
android:layout_width="match_parent"
android:layout_height="25dp"
android:gravity="center"
android:text="1"
android:background="#drawable/txtbg"
android:textColor="#color/red"
android:textSize="10sp"
android:textStyle="bold" />
The image is in png format with transparent background. TextView is inside a TableRow in TableLayout. This Layout is part of the ListView item - but I don't think it's the problem.
With background:
Without background:
In fact, there are 2 TextViews, one showing distance and the second numbers - the first one has no background. When I try to put a background to the second one - both texts dissapear.

I faced with the same issue. After some researching I still don't know reasons to provide to this situation. To solve it, I simply put a View with desirable background below TextView. Not pretty but works.

Related

How do I make a certain component have a relative layout with another component outside of its linear layout

So, the title may be confusing, but to put it in context:
I have an ImageButton component in my app display that should be on the opposite side of my ImageView, lined up perfectly, and to repeat this for any other item on the same list.
My question and doubt itself is how to do this when the ImageButton in this case is inside a LinearLayout while the ImageView is outside of it. Is there like a code line that can connect an outside element to a LinearLayout inside element.
Here's how my display looks:
item_contact.xml
The blue rectangle, being the LinearLayout, means everything inside belongs to it, but the call button looks to be the on the other side of the user pic, which is not inside the LinearLayout, which is what I wanted, the problem is this:
activity_main.xml
Each of the TextViews are above and below both the user picture and the call button, but because they both also belong to the LinearLayout, it's obvious it's because of the latter.
Now I tried fixing the problem by simply adding the user picture to the LinearLayout, which seems like the obvious answer, but I needed to be sure, because my call button isn't correctly aligned to the right:
<ImageView
android:id="#+id/iv_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/todo"
android:src="#drawable/ic_baseline_person_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="ImageContrastCheck" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#id/iv_image"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<TextView
android:id="#+id/tv_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:textColor="#color/purple_700"
android:textSize="18sp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/call_button"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginStart="248dp"
android:background="#1072E1"
android:contentDescription="#string/call"
android:minWidth="48dp"
android:src="#android:drawable/stat_sys_phone_call" />
<TextView
android:id="#+id/tv_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textSize="14sp" />
</LinearLayout>
My ImageButton's "right alignment" was only done with the manual positioning of the android:layout_marginStart which I set to 248dp by attempts. Surely there's a better way to do this, but I've yet to find a solution that works.
Lastly, there's also the aforementioned problem: I can't seem to fix the LinearLayout issue without having to backtrack the progress I've done and use new code lines or already existing ones to resolve the issue.
So:
How can I "connect" two components, one inside a LinearLayout and another not, with or without the use of constraints and/or RelativeLayouts, and do I really have to insert the outside component to the LinearLayout;
How can I forcefully align a component to the right without having to manually push it with margin inputs (attempts);
Is there a way to know exactly how to connect a component to another by using constraints accurately, so it repeats that process through the entire contact list?.
I would really like if someone could answer at least one of the listed questions or, even better, resolve one of the most developed questions, where I show some images of reference.
Maybe even a suited tutorial for my case in specific that explains the ways of designing the layout of an app.
If more information is needed, I will gladly help, and I'll also try to answer to every response I can get.
Also, in case you're curious, here's my last question about the same app (already resolved):
"[AppName] stopped working" when I try to run my app on an AVD emulator
(Keep in mind that the problem at hand in this question has barely anything to do with this one.)

How to fix imageview positions but have variable textview above them in Android

I am currently working on an app and my layout is as follows:
I have a recyclerview holding all of my items, each item has a textview above an imageview. So the text view can expand up to 3 lines but only if needed. The recyclerview is using a gridlayout manager to display all of my items.
The problem is that currently when the text view expands to have more than 1 line it presses down the image instead of keeping it aligned with the other images in the row
What I currently have
What I want is to prevent the text view from pressing down on the image but instead build it's way up so that way the images stay normal and the text view will grow upwards like the image below.
What I want
Is there any way to achieve this? I would think it shouldn't be hard but I can't seem to find a way to accomplish this, or more likely, can't google the right terms to find the solution I'm looking for.
So I found an answer, I had to set two properties for my textview:
android:lines="3"
android:gravity="bottom"
so in the end each item had a layout below:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingStart="31dp"
android:paddingEnd="32dp">
<TextView
android:id="#+id/app_name"
android:layout_width="#dimen/product_list_image_dimensions"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/app_card_temp_name"
android:textSize="#dimen/product_list_text_size"
android:fontFamily="sans-serif-condensed"
android:lines="3"
android:textAlignment="center"
android:textColor="#color/app_name_product_list_color"
android:typeface="normal"
android:gravity="bottom" />
<ImageView
android:id="#+id/app_thumbnail"
android:layout_width="#dimen/product_list_image_dimensions"
android:layout_height="#dimen/product_list_image_dimensions"
android:layout_below="#id/app_name"
android:paddingTop="#dimen/product_list_text_bottom_padding"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true" />
</RelativeLayout>

EditText sometimes randomly not showing?

So I have an app that has this EditText. With some devices (generally the ones with higher resolutions), the EditText tends to randomly not show. However, it can be solved by restarting the app.
Here's a picture of how it should be:
And here's a picture of how it sometimes it randomly disappears:
It is important to clarify that the disappearing doesn't happen while the app is running, when you open the app, the editText is either there or not.
Thank you so much!
This is the XML for the EditText:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal|numberSigned"
android:ems="10"
android:id="#+id/abs"
android:editable="true"
android:numeric="decimal"
android:textAlignment="center"
android:textColor="#000000"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/btn"
android:layout_alignStart="#+id/btn"
android:layout_alignRight="#+id/btn"
android:layout_alignEnd="#+id/btn" />
android:layout_width="wrap_content"
The above line mean EditText will have same width as the size of text inside it. When EditText is empty it will be so small that you can't see.
You can fix this making EditText width same as its parent
android:layout_width="match_parent"
or you can fix width by providing your own width:
android:layout_width="80dp"

Android Widget layout with three buttons and text

I'd like to write a widget of dimension 3x1 that contains three equal buttons without a space in between. Instead of buttons, any other kind of View would be ok, as long as pushing them is possible.
I'd like to "overlay" text over all the three buttons so the text is not wrapped within one of the buttons.
What I have tried so far is this:
<TextView
android:id="#+id/update"
style="#android:style/TextAppearance.Medium"
android:layout_width="69dp"
android:layout_height="64dp"
android:layout_gravity="center"
android:background="#drawable/att_rec_red"
android:gravity="center_horizontal|center_vertical"
android:text="ABCDEFG" >
</TextView>
<TextView
android:id="#+id/update2"
style="#android:style/TextAppearance.Medium"
android:layout_width="70dp"
android:layout_height="64dp"
android:layout_gravity="center"
android:background="#drawable/att_rec_green"
android:gravity="center_horizontal|center_vertical"
android:text="ABCDEFG" >
</TextView>
<TextView
android:id="#+id/update3"
style="#android:style/TextAppearance.Medium"
android:layout_width="70dp"
android:layout_height="64dp"
android:layout_gravity="center"
android:background="#drawable/att_rec_blue"
android:gravity="center_horizontal|center_vertical"
android:text="ABCDEFG" >
</TextView>
What I did not like are the explicit widths of the TextViews. I had to fine-tune these numbers so the three TextViews fit exactly into the space of the widget. Is there a better way to do this?
Next question:
I'd like to place ONE text into / over these three TextViews (spanning all of them), but (of course) the text is specific to a single TextView. I could place three different text messages in there, but not one that spans all of them.
Is there a way to "overlay" text and still have the buttons visible and active (they can be pushed)?
As an alternative: Is it possible to have just ONE TextView and distinguish where within the TextView a push happened? I did not find any example for this but as it is possible to detect where within a View a push event happened, is it possible to detect that within the context of a widget? The setting the notification is done per View:
remoteViews.setOnClickPendingIntent(R.id.update, pendingIntent);
Is there a way to evaluate the position in a View too?

TextView in all projects moved to the right

This is easily the weirdest problem I've ever faced.
So today, I created a new Android Project. The first layout xml had just a textview that has the following properties (its inside a relative layout):
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="124dp"
android:background="#80ffffff"
android:gravity="center_vertical"
android:text="Welcome"
android:textSize="48dp"
android:textStyle="bold" />
What I wanted was to have a textview that has text in its center. But the text STARTS from the center and goes out of screen towers the right side.
So I thought I must be doing something wrong. I went into one of my older projects (it was also open in eclipse). I opened an XML there, and shockingly, all the text there has also moved to the left (It starts from the center, rather than actually centering the text). It was fine yesterday. Here's the button:
<Button
android:id="#+id/gettingstarted"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/login"
android:layout_below="#+id/login"
android:layout_marginTop="10dp"
android:text="Getting Started"
android:textColor="#ffffff" />
I have no idea what happened. Why is the text no longer centered in buttons in all my projects? I'm in a really tough spot right now. Kindly help.
For your first problem try
android:gravity="center_vertical|center"
but for your text views in your all projects , it's a general question , maybe it's occured because of changing in your apps theme or projects styles

Categories

Resources