Android ListView does not show line spacing - android

I am trying to set the line spacing color using the following code, but no lines are displayed.
I am actually using the SwipeListView, but I do not think it matters
mylistview.setDividerHeight(1);
mylistviewsetBackgroundColor(Color.WHITE);
what am I doing wrong?

Not sure whether you can use just a color. A drawable will definitely work.
drawable/divider_white.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="1dip" />
<solid android:color="#ffffffff" />
</shape>
In your layout use
android:divider="#drawable/divider_white"

You can do it in xml adding these attributes in ListView
android:divider="#android:color/white"
android:dividerHeight="1dp"
Instead of color you can use any drawable

found it...
not sure why, but the order of calls are important...
mylistview.setBackgroundColor(Color.WHITE);
mylistview.setDividerHeight(1);

Related

How to draw outline stroke on text in TextView? (Kotlin)

I need to draw outline stroke on text in MaterialTextView. I saw that it is not that easy to do in older questions.
(In this for example: How do you draw text with a border on a MapView in Android?).
Is something changed right now? If we need to set it programmatically, can anyone help me with Kotlin method for this and explain how to make it? I saw answers but I don't know where to create attrs.xml file I never used it before.
You could define a rectangle shape in the res/drawable folder, let's call it rect_border.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke android:width="2dp"
color="#000" />
</shape>
And use it as android:background for your MaterialTextView:
<MaterialTextView
...
android:background="#drawable/rect_with_border" />

Android button border stay deafault after adding drawable file

I'm working on a project in android studio and I'm trying to change the border to my button.
My default button when I just add it to my grid look like this:
After adding new XML file (called box_solid_border.XML) in the drawable file that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="4dp"
android:color="#000000" />
</shape>
the result is that it's creating the next shape that I can see:
and that exactly what I want to add to my button.
when I come back to my XML at the main file and add to my button the next line:
as you can see in line 226 I'm adding the background that I just created for this button to the button. and near the line, there is the exact border that I want.
but in the application, the button still stays the same as the default one with no border added to him.
Like this:
Does someone know the reason that the drawable file doesn't affect the button?
If I'm doing the same thing for a textView or something else its works perfectly fine, just the button looks like not affected by the drawable extension to him.
Thank you!
You need to add this attribute to your button:
app:backgroundTint="#null"
If it has both attributes android:background and app:backgroundTint(if you are using the default theme for your application, it has a default value), the color specified by app:backgroundTint will be cover on the shape of drawable.
For border to button try to edit box_solid_border.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:color="#color/black"
android:width="5dp"/>
<corners
android:radius="8dp"/>
<solid
android:color="#color/colorAccent"/>
</shape>
In layout xml file
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/box_solid_border"
android:text="Button"
android:textColor="#fff"
android:textSize="30sp" />

how to create this text header shape in android

i design my app in photoshop and i create most of my design but i cant create this shape:
but i only can create rectangle with code below
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="80dp" android:height="30dp" />
<solid
android:color="#color/blue"/>
</shape>
anyone can help me?
thanks for yr reply
Do you absolutely need it to be an android shape? Or could you simply use a png?
Check this out on how to make a custom button: http://developer.android.com/guide/topics/ui/controls/button.html
Or for the most flexibility add an imageview:
http://developer.android.com/reference/android/widget/ImageView.html
And then set an ontouch listener to it:
How to implement touch listener on image?
Hope this helps.

How to disable click style in android GridView

I have a android.widget.GridView and I'm setting setOnItemClickListener() on it. It works perfectly but adds a style to the UI when a cell is clicked. Any ideas how to remove this style?
Ok thanks #Sam you got me on the right track. Could not get <item android:color="#00000000" />to work, I think for grids you need to use drawables along the lines of Android ListView Selector Color. In the end my code that works is
Java code:
mygrid.setSelector( R.color.empty_selector );
res/color/empty_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/transparent"/>
</selector>
res/color/transparent.xml:
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center" android:src="#drawable/transparent" />
Not sure if there had been an easier way but this has worked so I'm happy.
I believe you are referring to the color selector or color state list. You can probably create a dummy selector, that has no alternate values, then set it to the GridView with setSelector() in Java or android:listSelector in XML.
A dummy selector, it is transparent:
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:color="#00000000" />
</selector>

Creating an empty Drawable in Android

Creating a Drawable that is completely empty seems like a common need, as a place holder, initial state, etc., but there doesn't seem to be a good way to do this... at least in XML. Several places refer to the system resource #android:drawable/empty but as far as I can tell (i.e., it's not in the reference docs, and aapt chokes saying that it can't find the resource) this doesn't exist.
Is there a general way of referencing an empty Drawable, or do you end up creating a fake empty PNG for each project?
For me it didn't work when I tried to use #android:id/empty when making an empty drawable. For me, #android:color/transparent was the one.
I use an empty ShapeDrawable, i.e. create my own drawable/empty.xml containing just <shape/>
<shape />
creates an empty shape and does the trick for me. Or create a file empty_drawable.xml containing:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" />
so you can use it elsewhere.
You can also make a shape disappear when the view it is used in is not enabled by creating my_disablable_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<shape android:shape="oval">
<size android:height="10dp" android:width="10dp" />
<solid android:color="#android:color/white" />
</shape>
</item>
<item android:state_enabled="false">
<shape />
</item>
</selector>
Use #android:color/transparent and don't forgot add android:constantSize="true" on <selector>
For me, using #android:drawable/empty would show an error and prevent compiling. Using #android:id/empty fixed the error and let me compile, but showed "NullPointerException: null" in the Eclipse Layout editor. I changed it to #android:color/transparent and now everything is fine.
I can't vote up yet or I would have up'ed Emil's answer.
#null in XML has the same effect as using a null as a Drawable in Java.
Kai, I don't know why this is the case, but I've gotten the same issue. I think it might be related to the version of Android you're compiling for? In any case, I found that simply using #android:id/empty where you would use #android:drawable/empty does the trick.
I had the same problem. My App crashed with an empty vector image. I solved it by adding a transparent/invisible path element. I tested it with API 22 and 30.
ic_empty.xml:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:strokeAlpha="0" android:pathData="M0,12h24"/>
</vector>
To create an empty Drawable image, you may use ShapeDrawable with transparent color:
val shapeDrawable = ShapeDrawable(OvalShape())
shapeDrawable.paint.color = context.getColor(android.R.color.transparent)
If the image size is important, use:
shapeDrawable.intrinsicWidth = 100
shapeDrawable.intrinsicHeight = 100

Categories

Resources