Question mark (?) in XML attributes for Android
The question mark means it's a reference to a resource value in the currently applied theme. See the linuxtopia Android Dev Guide or the android.com Dev Guide for more about it.
\?
escapes the question mark.
When to use a question mark for XML attributes?
the ?
is for referencing style attributes; the documentation explains it:
To reference a style attribute, the name syntax is almost identical to the normal resource format, but instead of the at-symbol (
@
), use a question-mark (?
), and the resource type portion is optional.
?[<package_name>:][<resource_type>/]<resource_name>
Question mark in XML as value
Try to use
<string name="questionMark">\?</string>
and you can check this docs to handle special characters.
I've got a question mark to TextInputEditText. What does it mean?
Check out this similar question: https://stackoverflow.com/a/55541787/8242091.
(Would have commented but don't have enough reputation)
Question mark instead of RTL field
Thanks to @anil
Finally i find two way for problem :
- change source file encoding in
Settings>File Encoding
:
if problem not resolve :
- First way + Using Strings from resources
(R.String.nameOfString)
instead type them directly in Java source code
initialize XML attributes in Custom View
You will want to use the AppCompat version of what you want to use, such as the AppCompatImageView as layoutParams would then be supported. One thing I also saw wrong: you must specify the context and all of the included attributes in the constructor of the class:
(context : Context, attrs : AttributeSet)
These will be auto assigned by the OS so nothing really needs to be done with them, but they must be there. Here is what I have for you:
class CustomImageView(context: Context,
attrs : AttributeSet) : AppCompatImageView(context, attrs) {
init {
applyDefaults()
}
private fun applyDefaults(){
val height = 130
val width = 300
layoutParams = ViewGroup.LayoutParams(width, height)
}
}
Get the current layout parameters by getting them from the base class, which would be AppCompatImageView. Then set the layout parameters to be the height and width you want as an integer.
What's the difference between @android: and ?android:
(from this answer and its comments)
Prefixing the ID with a question mark indicates that you want to access a style attribute that's defined in a style theme, rather than hard-coding the attribute, as explained in Referencing Style Attributes.
More specifically, the ?
implies an extra level of indirection. Think of it as dereferencing a theme attribute to fetch the resource it points to rather than referring to the attribute itself. You see this with ?android:attr/foo
Related Topics
Making Data Persistent in Android
Fragment Onresume() & Onpause() Is Not Called on Backstack
Showing Empty View When Listview Is Empty
Android Studio How to Package Single Aar from Multiple Library Projects
Firebase (Fcm) How to Get Token
How to Get a Working Vertical Seekbar in Android
How to Play Youtube Video in My Android Application
How to Create a Popup Window (Popupwindow) in Android
How to Tell If 'Mobile Network Data' Is Enabled or Disabled (Even When Connected by Wifi)
Using Getresources() in Non-Activity Class
Continue Service Even If Application Is Cleared from Recent App
Android - Linearlayout Horizontal with Wrapping Children
Question Mark () in Xml Attributes for Android
Detect Scroll Up & Scroll Down in Listview
Android Sharedpreference Security
Get Only Email Address from Contact List Android