Questions tagged [android-custom-view]

A tag for questions related to building and using custom graphical widgets on the Android platform.

An Android custom view is created by extending the base class of all Android widgets, the View class. If the custom view is designed to hold other views, then the ViewGroup class should be extended instead. A custom view that extends the View class has several methods that should be implemented in order to make the custom view work, methods like onMeasure() and onDraw(). More info about custom views can be found at:

3300 questions
223
votes
5 answers

Same-named attributes in attrs.xml for custom view

I'm writing a few custom views which share some same-named attributes. In their respective section in attrs.xml I'd like to use the same names for attributes:
214
votes
20 answers

How to make custom dialog with rounded corners in android

What I am trying to do: I am trying to make a custom dialog in android With rounded corners. What is happening: I am able to make custom dialog but it doesn't have rounded corners. I tried adding a selector but still I couldn't achieve rounded…
Devrath
  • 42,072
  • 54
  • 195
  • 297
155
votes
6 answers

Do I need all three constructors for an Android custom view?

When creating a custom view, I have noticed that many people seem to do it like this: public MyView(Context context) { super(context); // this constructor used when programmatically creating view doAdditionalConstructorWork(); } public…
Micah Hainline
  • 14,367
  • 9
  • 52
  • 85
131
votes
6 answers

How to get an enum which is created in attrs.xml in code

I created a custom View (find it here) with an declare-styleable attribute of type enum. In xml I can now choose one of the enum entries for my custom attribute. Now I want to create an method to set this value programmatically, but I can not access…
Informatic0re
  • 6,300
  • 5
  • 41
  • 56
111
votes
6 answers

How to use View Binding on custom views

View Binding got released as part of Android Jetpack Docs: https://developer.android.com/topic/libraries/view-binding My question is, how to use view binding with custom views. Google documentation has only show-cased Activity and fragment. I tried…
Emad Razavi
  • 1,903
  • 2
  • 17
  • 24
110
votes
12 answers

how to customize snackBar's layout?

Is there any method to change the layout of a snackBar to custom View? Now it comes black and we can change the background color. But I don't know the right way to inflate a new layout and making it as snackBars background? Thanks...
97
votes
4 answers

How to use isInEditMode() to see layout with custom View in the editor

I must edit a software that have a custom view, when I try to edit layout xml, Eclipse says me: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse But I have no idea about how and where I must use isInEditMode() in…
AndreaF
  • 11,975
  • 27
  • 102
  • 168
84
votes
8 answers

Different resolution support android

Edited Question: Mobile Resolution: I would like to design different screen dpi like following resolutions. 320x480,480×800,540x960,720x1280 (Samsung S3),1080x1920 (S4, Nexus5,Nexus 5x, Moto G4),2560 x 1440 (Nexus 6, Nexus 6p, Samsung edge) Tablet…
79
votes
4 answers

Fragment vs. Custom View in Android

The Fragment and Custom View can achieve the similar function, I know that fragment is more re-usable comparing with custom view, any other benefits/enhancements for using Fragment? Is fragment supposed to replace Custom View, or just a enhancement…
Kai
  • 916
  • 1
  • 7
  • 10
66
votes
14 answers

How to remove the top and bottom space on textview of Android

When I include the below XML to layout file, I can see the below image. If you see it, you could realize that the TextView has top and bottom space.…
mooongcle
  • 3,987
  • 5
  • 33
  • 42
66
votes
3 answers

Custom view ... overrides onTouchEvent but not performClick

I get this warning (from the question title) in a custom Android view I am developing. Why do I get warned? What's the logic behind it i.e. why is it a good practice to also override performClick when you override onTouchEvent?
peter.petrov
  • 38,363
  • 16
  • 94
  • 159
66
votes
6 answers

Android Studio layout editor cannot render custom views

In Android Studio, the layout editor cannot preview custom views in xml. Very simple example: public class MyCustomView extends FrameLayout { public MyCustomView(Context context) { super(context); } public MyCustomView(Context…
Naetmul
  • 14,544
  • 8
  • 57
  • 81
55
votes
7 answers

No resource identifier found for attribute '...' in package 'com.app....'

I've imported a project from Eclipse to Android studio. It utilizes a custom view: xmlns:app="http://schemas.android.com/apk/res-auto" I get errors in the lines below from activity_ro.xml file like: "Error:(136) No resource identifier found for…
kevthanewversi
  • 3,686
  • 4
  • 27
  • 27
55
votes
2 answers

Setting textSize in custom view results in huge text

I'm calling the following in the constructor of my custom view: private void style(Resources.Theme theme, AttributeSet attrs) { TypedArray a = theme.obtainStyledAttributes( attrs, R.styleable.StackedTextView, …
loeschg
  • 29,961
  • 26
  • 97
  • 150
52
votes
4 answers

MonoDroid: Error when calling constructor of custom view - TwoDScrollView

I am building an Android application that uses the custom-built TwoDScrollView found here: http://blog.gorges.us/2010/06/android-two-dimensional-scrollview/ This same class can be found referenced at several other websites, and others on Stack…
1
2 3
99 100