Hey anyone know why this (see in the picture) happens?
It's happens for Xiaomi MiA1, while on Nokia 7.1 works fine.
My xml view layout
FrameLayout - root
ScrollView
RelativeLayout
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/til_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/profile.EMAIL"
android:theme="#style/TextInputLayoutTheme"
android:margin="16dp"
android:paddingBottom="8dp"
app:layout_constraintTop_toBottomOf="#+id/phone_wrapper"
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:textSize="16sp"
android:textColor="#color/darkTextColor"
android:imeOptions="actionDone"
tools:text="Email"
/>
</com.google.android.material.textfield.TextInputLayout>
I think that putting TextInputLayoutTheme is not relevant here, since I only manipulate with view's colors
The error message text gets cut off if you are setting the error on a TextInputLayout more than once.
So every time you are setting TextInputLayout error message text, just set it to null first.
textInputLayout.setError(null);
textInputLayout.setErrorEnabled(false);
textInputLayout.setError("Error Message");
Layout Inspector shows that even if there is some space for the error it doesn't draw view in all of it. Everything there is in LinearLayouts (and one simple FrameLayout) so there is no way something would overlap it, paddings are set to 0, there is no code changing height or something suspicious in the implementation, so I don't know what might be a reason of such behaviour.
Although I've found some solution which works. You need to find in TextInputLayout a view holding error (with id textinput_error) and add some small padding to it. I've done it by extending TextInputLayout and adding such code into init.
val errorTV = findViewById<TextView>(R.id.textinput_error)
errorTV.updatePadding(top = 4)
There is already issue on issue tracker - https://issuetracker.google.com/issues/116747167 so lets hope Google will fix it some day.
I resolved issue by saving and restore LayoutParams:
final ViewGroup.LayoutParams params = textInputLayout.getLayoutParams();
textInputLayout.setError(errorMessage);
textInputLayout.setLayoutParams(params);
I resolved issue by increasing size of error font to 14sp (orginal is 12sp)
<com.google.android.material.textfield.TextInputLayout
[...]
app:errorTextAppearance="#style/MyProfile.Error">
<style name="MyProfile.Error" parent="TextAppearance.Design.Error">
<item name="android:textSize">14sp</item>
</style>
Although as Shabbir Dhangot said I may be that setting TIL.setErrorEnabled(true) may help for some else.
As some have already pointed out, this is a known bug. See https://issuetracker.google.com/issues/116747167
I solved this by doing something like this (note that below code is Kotlin, so != works on Strings):
if(myInputLayout.error != error){
myInputLayout.error = error
}
I know it is not the best solution, but you can add a \n to the beginning of your error message.
For example, if your error is Error, just change it to \nError.
If you want to change the size of the \n you can use:
String newLine = "\n";
String errorMessage = "Error";
SpannableString spannableErrorMessage = new SpannableString(newLine + errorMessage );
spannableName.setSpan(new TextAppearanceSpan(activity, R.style.my_style),0,a.length(), 0);
spannableName.setSpan(new RelativeSizeSpan(2.0f), a.length(), a.length() + 1, 0);
You can use this Kotlin extension:
/**
* Fix a bug with [TextInputLayout] that cut the error text when setting the same text twice.
*/
fun TextInputLayout.setFixedError(errorTxt: CharSequence?) {
if (error != errorTxt) {
error = errorTxt
}
}
Usage:
yourTextInput.setFixedError("Your error text")
I have done the seekbar but I need to do the customization like the below image.
I used the code like this
<SeekBar
android:id="#+id/seekbarPoints"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="-16dp"
android:layout_marginTop="#dimen/small"
android:max="0"
android:progress="0"
android:progressDrawable="#drawable/shape_seekbar_points_style"
android:thumb="#null" />
if (TextUtils.isDigitsOnly(maxPoints)) {
int maxP = Integer.parseInt(maxPoints);
mBinding.seekbarPoints.setMax(maxP);
if (!TextUtils.isEmpty(points)) {
int p = (int) Double.parseDouble(points);
mBinding.seekbarPoints.setProgress(p);
}
}
mBinding.seekbarPoints.setProgressDrawable(ContextCompat.getDrawable(getContext(), R.drawable.shape_seekbar_points_style));
In this image there should be a current points showing textView like the image below
Please suggest some solution for this
Thanks in advance.
you can use following library to achieve your goal
take a look below libray
Library 1
Library 2
Library 3
Library 4
I need to hide the domain values in a linegraph. Could someone please help me?
plot0.setDomainBoundaries(0, windowsize, BoundaryMode.FIXED);
plot0.addSeries(series0, formatter);
plot0.setDomainStepMode(XYStepMode.INCREMENT_BY_VAL);
plot0.setDrawRangeOriginEnabled(true);
plot0.setTicksPerRangeLabel(5);
plot0.getLegendWidget().setVisible(false);
plot0.getGraphWidget().getBackgroundPaint().setColor(Color.BLACK);
plot0.getGraphWidget().getGridBackgroundPaint().setColor(Color.BLACK);
plot0.setTicksPerDomainLabel(5);
plot0.centerOnRangeOrigin(0);
plot0.setRangeBottomMax(-20);
plot0.setRangeTopMin(20);
plot0.setRangeLowerBoundary(-75, BoundaryMode.FIXED);
plot0.setRangeUpperBoundary(75, BoundaryMode.FIXED);
plot0.setRangeStep(XYStepMode.INCREMENT_BY_VAL, 25);
plot0.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 240);
UPDATE:-
Library version
compile 'com.androidplot:androidplot-core:0.9.7'
I have modified the XML with as below. But the changes are not reflecting unless I modify it inside the code.
<com.androidplot.xy.XYPlotZoomPan
android:id="#+id/dynamicXYPlot0"
androidplot.renderMode="use_background_thread"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginTop="20dp"
android:background="#android:color/black"
ap:backgroundColor="#000000"
ap:borderColor="#000000"
ap:label="Lead I"
ap:domainTickLabelTextColor="#00000000"
ap:domainOriginTickLabelTextColor="#00000000"
ap:gridPaddingBottom="1dp"
ap:labelTextSize="10sp" />
I'd suggest trying to do it in XML by adding these params:
ap:domainTickLabelTextColor="#00000000"
ap:domainOriginTickLabelTextColor="#00000000"
ap:gridPaddingBottom="1dp"
This basically sets the tick label color to be completely transparent and removes the extra padding needed to display those labels below the grid.
Before:
After:
Got the solution. Adding these 2 lines worked.
plot0.getGraphWidget().getDomainTickLabelPaint().setColor(Color.TRANSPARENT);
plot0.getGraphWidget().getDomainOriginTickLabelPaint().setColor(Color.TRANSPARENT);
I am learning Android and the following is part of an assignment.
I need to write some text in an Android layout with the first letter in drop caps, like the following text:
I looked up the web and did not find many answers. Is there a style option or some property that I could use?
At the moment, I am thinking of the following options. Please suggest what is the best way to do such a thing
Use an image for the first letter
Write the first letter separately in a big font.
Any suggestions would be helpful.
You can use a RelativeSizeSpan.
final String someText = "A long time ago in a galaxy far, far away";
final SpannableString ss = new SpannableString(someText);
ss.setSpan(new RelativeSizeSpan(5f), 0, 1, 0);
There's a library written by Novoda in which you can add a DropCap https://github.com/novoda/spikes/tree/master/drop-cap
Here's an image from the demo app:
Please follow GitHub sample app
https://github.com/datanapps/CapTextView
<datanapps.captextview.CapTextView
android:id="#+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:padding="5dp"
app:layout_constraintTop_toBottomOf="#+id/text1"
app:capsDropNumber="2"
app:capFont="#font/eb_garamond_regular"
app:capTextColor="#color/purple_700"
app:capTextSize="#dimen/cap_text_size"
app:bodyTextColor="#color/purple_700"
app:bodyTextSize="#dimen/body_text_size"
app:bodyTextFont="#font/eb_garamond_regular"
/>
Hope it will help
I have the following layout (virtually empty):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/set_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="content desc"
android:orientation="vertical" >
<TextView android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
</LinearLayout>
The Activity class contains the following:
public class TestActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
}
When I run this on my mobile device I get the following error:
SpannableStringBuilder
SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
I have tried this with and without the TextView and the error still remains, I must be doing something fundamentally wrong for such a basic layout to cause this.
Does anyone have any ideas on how I can get this to load without the error?
I have run into the same error entries in LogCat. In my case it's caused by the 3rd party keyboard I am using. When I change it back to Android keyboard, the error entry does not show up any more.
Because the error you're getting is not related to an EditText, then it's not related to your keyboard.
The errors you are getting are not a result of your code; you probably are testing on a Samsung device that has Samsung's TouchWiz.
I had the same errors, then I tested on a Nexus S (also by Samsung, but pure Android OS without TouchWiz) and I didn't get this error.
So, in your case, just ignore these errors while testing on a device! :)
Looking at your code, I'm not sure why you're getting that error, but I had this same error but with EditText fields.
Changing android:inputType="text" (or any of the other inputType text variations) to android:inputType="textNoSuggestions" (or android:inputType="textEmailAddress|textNoSuggestions", for example) fixed it for me.
You can also set this in Code with something like
mInputField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
Looks like Android assumes by default that EditText fields will have suggestions. When they don't, it errors. Not 100% confident in that explanation, but the above mentioned changes fixed it for me.
http://developer.android.com/reference/android/text/Spanned.html#SPAN_EXCLUSIVE_EXCLUSIVE
Hope this helps!
On your android phone go to:
settings -> application manager -> all -> samsung keyboard and then click on "clear cache"
(delete all data collected by this application).
Try using the default Android keyboard it will disappear
Make clear you have pass a value in your MainAcitivity for the following methods onCreateOptionsMenu and onCreate
In some cases, the developer deletes the "return super.onCreateOptionsMenu(menu)" statement and changed to "return true".
This worked for me...on every device
<EditText
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="15sp"
android:layout_centerVertical="true"
android:textColor="#000"
android:id="#+id/input_search"
android:background="#null"
android:inputType="text"
android:hint="Enter Address, City or Zip Code"
android:imeOptions="actionSearch"
/>
In Java code:
mSearchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if(actionId == EditorInfo.IME_ACTION_SEARCH
|| actionId == EditorInfo.IME_ACTION_DONE
|| keyEvent.getAction() == KeyEvent.ACTION_DOWN
|| keyEvent.getAction() == KeyEvent.KEYCODE_ENTER){
//execute our method for searching
}
return false;
}
});
I had the same warning and found that removing an unused #id got rid of the warning. For me it was obvious as the #id was associated with a growing list of textViews linked to a database, so there was a warning for each entry.
Masood Moshref is right, this error occur because the option menu of Menu is not well prepared by lacking "return super.onCreateOptionsMenu(menu)" in onCreate() method.
To try to debug this error, first go to your android terminal / console and execute this command:
ps | grep THE_ERROR_PID_YOU_GET_(IT_IS_A_NUMBER)
then if the output comes out as your app... it is your app causing the error. Try to look for empty Strings that you pass into the layout.
I had this exact same problem and it was my fault as I was passing an empty String into my layout. After changing the "" to " " this error went away.
If you don't get your app from the console output, then it is something else causing it (probably, as others said, the android keyboard)
I have faced the same issue. I almost wasted almost couple of weeks to resolved this issue.
Finally I had on doubt on myself and tried to create another project by copy and paste some startup files like SplashScreen & LoginScreen.
But with the same code still i was getting SPAN_EXCLUSIVE_EXCLUSIVE.
Then i have removed the handler code from splash screen and tried again and Wow its working.
I am not getting SPAN_EXCLUSIVE_EXCLUSIVE issue in logcat.
I wondering, why it is? till the time did not get any other solution but by removing handler from splash screen it is working.
Try and update here if it is resolved or not.
Check if you have any element such as button or text view duplicated (copied twice) in the screen where this encounters. I did this unnoticed and had to face the same issue.
I ran into this problem too when I copied some text from the Internet. My solution is to trim the text/remove formatting before doing any further processing.
I had the same problem but with a listView.... i solved it because i was using a wrong R.id.listView that list View needed to have a value, in my case it was strings that i saved on listView2... so the right code was R.id.listView2
I had the same problem then i fixed it by following code!
text = (EditText)findViewById(R.id.TextVoiceeditText);
text.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
this error also occurs due to changed API URL. try hitting the URL you are using in postman and c if it's working properly.
rechecking the APIs solved my problem
try avoiding use of view in xml design.I too had the same probem but when I removed the view. its worked perfectly.
like example:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:inputType="number"
android:textColor="#fff" />
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#f9d7db" />
also check and try changing by trial and error android:inputType="number" to android:inputType="text" or better not using it if not required .Sometimes keyboard stuck and gets error in some of the devices.
In my case, the EditText fields with inputType as text / textCapCharacters were casing this error. I noticed this in my logcat whenever I used backspace to completely remove the text typed in any of these fields.
The solution which worked for me was to change the inputType of those fields to textNoSuggestions as this was the most suited type and didn't give me any unwanted errors anymore.
in my case i click on recent apps shortcut on my cell phone and close all apps. This solution always work for me, because this error not related to code.
**DONT PUT SET TEXT IN TEXT WATCHER**etSearch.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable) {
visibleResultList = false
if (s.toString().length != 0) {
getSearchSuggetion(no_of_rec, 0, s.toString())
} else {
// etSearch.setText("")
}
Log.e("text_change","============"+s.toString())
}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
}
})
To solve this problem just add android:usesCleartextTraffic="true" in your AndroidManifest.xml file which is at ..\app\src\main\AndroidManifest.xml just like bellow...