Android Talkback contentDescription can not be read out in xml file - android

I set android:contentDescription in xml file. But it can't be read out in Talkback mode. If I call setContentDecsription in java code, it works. I try to getContentDescription in jave code, it returns null. It seems the android:contentDescription in xml file does not work. I don't know why.
Any suggestion is appreciated.
android:id="#+id/view_delete"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
android:paddingBottom="32dp"
android:paddingLeft="5dp"
android:paddingStart="5dp"
android:paddingTop="8dp"
android:contentDescription="Delete"
android:scaleType="fitCenter"
android:visibility="invisible"
android:src="#drawable/delete"

Related

Android : Class not allowed to be inflated android.widget.Switch

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="#string/general_dts_title"
style="#style/TextAppearance.Compat.Notification.Line2"
android:layout_alignParentBottom="false"
android:layout_alignBottom="#+id/imgToggle"
android:textSize="16sp" />
<Switch
android:id="#+id/imgToggle"
android:layout_width="42dp"
android:layout_height="28dp"
android:layout_gravity="right"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp" />
</RelativeLayout>
StatusBar: Caused by: android.view.InflateException: Binary XML file line #338 in com.dts.dtsxultra:layout/view_notification_sample: Class not allowed to be inflated android.widget.Switch ...
Could you please help.
I tried removing background attribute, but still it is not working.
I have tried the above piece of code, without giving the style to the textview, it works great. The error that you are facing may not be because of the piece of code.
RemoveView only allows some layout and widget to inflate. android.widget.Switch as in the error you are getting is not supported by RemoteView. You can see the list of supported views here

Android TextView unwanted padding issue

I am having issue with android TextView. having unwanted spacein TextView,
the space is coming only sometimes. For your reference attached image above, you can see some extra space on the right end of TextView. Please help me guys.
here is the xml code
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:ellipsize="end"
android:padding="0dp"
android:gravity="start"
android:text="#{message.message}"
android:textColor="#android:color/white"
android:textColorLink="#android:color/white"
android:textIsSelectable="true"
android:textSize="14sp"
tools:text="this is the problem i am having please helpme to find a solution" />
you can use this library to justify textview
https://github.com/navabi/JustifiedTextView
<ir.noghteh.JustifiedTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="25dp"
xmlns:noghteh="http://noghteh.ir"
noghteh:text="text here"
noghteh:textColor="#color/text"
noghteh:textSize="18sp"/>

Why character / cuts the text in TextView if maxLines = 1?

WHAT I HAVE
I have a TextView who is showing a URL with "https://" prefix:
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="test2"
android:maxLines="1"
android:ellipsize="marquee"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#color/primary_text"
android:id="#+id/txvNomEntornIversio" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="https://test2.sdasasdasdfasdfasdffasdfasdfasdf.sdffd"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="10dp"
android:textSize="13sp"
android:textStyle="italic"
android:id="#+id/txvUrlEntorn"/>
</LinearLayout>
WHAT IS THE PROBLEM?
The result in android studio preview and in device after execute the code was:
If execute previous code:
If I remove the "/" symbols:
If I move the symbol in other position:
WHAT I NEED
I need to show the prefix "https: //" with maximum letters to fit the available space.
WHAT I TRIED
I tried to read documentation (setEllipsize block) and search in stackoverflow, searching for some reference with this symbol and nothing found.
I tried also to scape the symbols with no effect.
Anyone know why it occurs and can help me? Thanks in advance!
UPDATED LAYOUT
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/icon_unchecked"
android:layout_marginRight="10dp"
android:id="#+id/txvIconChecked"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="test2"
android:maxLines="1"
android:ellipsize="marquee"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#color/primary_text"
android:id="#+id/txvNomEntornIversio" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="https://mydomain.asdfasdasdfasdfasdffasdfasdfasdf.cat"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="10dp"
android:textSize="13sp"
android:textStyle="italic"
android:id="#+id/txvUrlEntorn"/>
</LinearLayout>
</LinearLayout>
UPDATE 2
Thanks to Teiky, we have found that this problem occurs only in versions lower than API 23. It may be a bug?
The option (deprecated) Android: SingleLine = "true" seems to work correctly in all versions! Instead, the new option android: MaxLines with android: ellipsize only works for 23 ...
At the moment, the most viable option seems to ignore deprecated SingleLine ...
SOLUTION FOR ME
Finally, as I said in the last update, my solution was to continue using android: SingleLine = true even if it is marked as deprecated.
Teikyo seconds, he tried a dipsositiu android 4.4.4 and worked well using MaxLines ellipsize ... and me, a device Lollipop I still cut the text to find the symbol / ...
Set in response Teikyo as good as it helped me to investigate the problem further. Thank you all for your help!
I tried your code and the URL is fully display.
Maybe you should check these parameters, if you have enough width to display the complete URL:
android:layout_width="0dp"
android:layout_weight="1"
UPDATE by xikitidistant:
The solution isn't the weight and width="0dp". This was a code improve. The solution for me is updated in the question. Thanks for your help.
android:maxLines="1"
android:ellipsize="end"

Error in ImageButtons at src:"#drawable/..." Top level element is not completed

Everytime I put a #drawable item it appears underlined in red. It worked before but I pressed one of the options in the light bulb that appears next to the line and then all drawables became errors. I can't find the problem... I'm working with Android Studio. I tried to rebuild, clean, reimport... and nothing solves the problem.
My code:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:shrinkColumns="*" android:stretchColumns="*" android:background="#ffffff">
<TableRow
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:id="#+id/back"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:background="#null"
android:src="#drawable/backstate" /> /////////////////ERROR in "#drawable/backstate" (Underlined in red)
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:id="#+id/blanc"
android:layout_marginTop="50dp"
android:layout_marginLeft="20dp"
android:background="#null"
android:src="#drawable/blancstate"/> /////////////////SAME ERROR
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:id="#+id/groc"
android:layout_marginTop="50dp"
android:layout_marginRight="20dp"
android:background="#null"
android:src="#drawable/grocstate"/> /////////////////SAME ERROR
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:id="#+id/taronja"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:background="#null"
android:src="#drawable/taronjastate"/> /////////////////SAME ERROR
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:id="#+id/vermell"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:background="#null"
android:src="#drawable/vermellstate"/> /////////////////SAME ERROR
</TableRow>
</TableLayout>
All xml states are correct, layouts are well formed, i didn't change anything from the code, and by clicking that option that I didn't remember, all drawables started to give me errors.
ERROR DESCRIPTION: Top level element is not completed. Valid XML document must have a root tag.
Anyway the document is well formed... And it says the same error each time I write "#drawable/..."
EDIT: I found the origin of the problem. android namespace is the problem, if I change it for tools namespace it works. tools:src="#drawable/vermellstate" for example.
Can anyone help me please?
Try this:
Select item that is displaying error, then press alt + enter on the drawable item which calls error (for example:"#drawable/vermellstate") and select "Uninject language/reference"
Could be the case that you injected language by mistake.
If you are using Android Studio right click the code in question then->Local History->Show History and revert to a time prior to "Language Injection Configuration Update" .
Hope it helped,
Best of luck !

Cannot resolve symbol 'container' - Android Studio

I just created a new projet, building some layouts, writing some code. Everything was fine except I got this error as shown in the picture below.
I tried to remove and type it again and when typing 'R.id.', there was no 'container' showing up in the list. So that means theres no problem with my R file, just that the 'container' word lost somewhere.
Those code above are actually default code in onCreate() method in your main activity everytime you create a new project in Android Studio. (I actually tried to create a new project to compare and yes it's the same, and without error as it's brand new.).
All I did was comment out the if statement block so the error goes away, and the application has run just fine on the emulator. I just don't know why I got that problem and how I can handle it as I may need to do that in the future. Thank you!
Edit after #Raghunandan has mentioned: Below is my xml.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/provide_information"
android:id="#+id/provideInfoButton"
android:layout_alignParentTop="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/take_picture"
android:id="#+id/takePictureButton"
android:layout_below="#+id/provideInfoButton"
android:layout_alignParentLeft="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_below="#+id/takePictureButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/classNameTextView"
android:layout_above="#+id/personNametextView2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="44dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginBottom="38dp"
android:layout_above="#+id/emailTextView"
android:layout_alignLeft="#+id/emailTextView"
android:id="#+id/personNameTextView" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/emailTextView"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/classNameTextView"
android:layout_marginBottom="82dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/send_button"
android:id="#+id/sendButton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
The reason is that I changed the root layout to RelativeLayout (the default of Android Studio was FrameLayout which has an id of "container"). My bad :). Thanks for mentioning about posting the xml file. I have not noticed that as I'm not as familiar with Android Studio as with Eclipse yet.

Categories

Resources