Comments (11)
Could you find the total height of the hint text and the height of the view, then place the top of the hint half of its height above the middle of the view?
from android-floatinglabel-widgets.
Hi,
main issue on my side is time, not finding where the problem is. If you feel like contributing, feel free to fork the project and submit a pull request that fixes the issue.
The idea is to have the hint text aligned to the bottom of the EditText text when that one is empty.
from android-floatinglabel-widgets.
Ok! I've solved the problem. First of all I thought that the problem is in difference of styles of TextView and EditText (here is all ok). Then i started to check the java classes. So the problem is here:
FloatingLabelTextViewBase:
@Override
protected void afterLayoutInflated(Context context, AttributeSet attrs, int defStyle) {
super.afterLayoutInflated(context, attrs, defStyle);
// Load custom attributes
final int drawableRightId;
final int drawableLeftId;
final int drawablePadding;
final int inputWidgetTextAppearance;
final int inputWidgetTextColor;
final float inputWidgetTextSize;
if (attrs == null) {
inputWidgetTextAppearance = -1;
inputWidgetTextColor = 0xaa000000;
inputWidgetTextSize = getResources().getDimensionPixelSize(R.dimen.flw_defaultInputWidgetTextSize);
drawableLeftId = getDefaultDrawableLeftResId();
drawableRightId = getDefaultDrawableRightResId();
drawablePadding = 0;
} else {
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatingLabelTextViewBase, defStyle, 0);
drawableRightId = a.getResourceId(R.styleable.FloatingLabelTextViewBase_android_drawableRight, getDefaultDrawableRightResId());
drawableLeftId = a.getResourceId(R.styleable.FloatingLabelTextViewBase_android_drawableLeft, getDefaultDrawableLeftResId());
drawablePadding = a.getDimensionPixelSize(R.styleable.FloatingLabelTextViewBase_android_drawablePadding, 0);
inputWidgetTextAppearance = a.getResourceId(R.styleable.FloatingLabelTextViewBase_flw_inputWidgetTextAppearance, -1);
inputWidgetTextColor = a.getColor(R.styleable.FloatingLabelTextViewBase_flw_inputWidgetTextColor, 0xaa000000);
inputWidgetTextSize = a.getDimension(R.styleable.FloatingLabelTextViewBase_flw_inputWidgetTextSize, getResources().getDimensionPixelSize(R.dimen.flw_defaultInputWidgetTextSize));
a.recycle();
}
final TextView inputWidget = getInputWidget();
inputWidget.setCompoundDrawablesWithIntrinsicBounds(drawableLeftId, 0, drawableRightId, 0);
inputWidget.setCompoundDrawablePadding(drawablePadding);
if (inputWidgetTextAppearance != -1) {
inputWidget.setTextAppearance(getContext(), inputWidgetTextAppearance);
}
inputWidget.setTextColor(inputWidgetTextColor);
//inputWidget.setTextSize(TypedValue.COMPLEX_UNIT_PX, inputWidgetTextSize);
inputWidget.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (!isFloatOnFocusEnabled()) return;
if (hasFocus) {
floatLabel();
} else {
if (getInputWidget().getText().length() == 0) {
anchorLabel();
}
}
}
});
}
if you comment this line
//inputWidget.setTextSize(TypedValue.COMPLEX_UNIT_PX, inputWidgetTextSize);
everything works fine!
from android-floatinglabel-widgets.
Also I've noticed that if I specify TypedValue.COMPLEX_UNIT_SP - everything works fine but the text size is big.
from android-floatinglabel-widgets.
Ok. But we need to be able to set the text size. So there must be something else we can do to make both work.
from android-floatinglabel-widgets.
Yes I know, but this is the direction to continue searching of the solution
from android-floatinglabel-widgets.
Ok! Here is another solution without commenting code blocks. I've done comparison of styles, text widgets and some experiments. Why does widgets behave like this - I don't know. But there is more beautiful (in my point of view) solution:
FloatingLabelTextViewBase:
final TextView inputWidget = getInputWidget();
inputWidget.setCompoundDrawablesWithIntrinsicBounds(drawableLeftId, 0, drawableRightId, 0);
inputWidget.setCompoundDrawablePadding(drawablePadding);
inputWidget.setTextColor(inputWidgetTextColor);
inputWidget.setTextSize(TypedValue.COMPLEX_UNIT_PX, inputWidgetTextSize);
if (inputWidgetTextAppearance != -1) {
inputWidget.setTextAppearance(getContext(), inputWidgetTextAppearance);
}
Just replace the order of setTextSizу and setTextAppearance methods.
In your app layouts (where you use FloatingLabelItemPicker and for example FloatingLabelEditText) you must specify two attributes for the custom Fl... widgets:
app:flw_inputWidgetTextSize="14sp"
app:flw_inputWidgetTextAppearance="@android:style/TextAppearance.Medium.Inverse"
I thinks much better to add these attributes to the library's layout files.
P.S. These attrs is needed only by EditText and TextView (as I understand while was comparing their styles).
from android-floatinglabel-widgets.
Please note that instead of TextAppearance.Medium.Inverse we could use any TextAppearance styles. The main question is - to use the same appearance in EditText and TextView.
from android-floatinglabel-widgets.
But! Sorry for many messages. There is another problem - font size 14sp. When it uses 14sp - heights of widgets are not equal! I'll continue the searching
from android-floatinglabel-widgets.
Starting form the 18sp - all good
from android-floatinglabel-widgets.
Setting different drawable (with smaller size) - and the size of widget not increases.
from android-floatinglabel-widgets.
Related Issues (20)
- Text misaligned with text cursor HOT 2
- Gradle support HOT 1
- Style contains key with bad entry HOT 2
- Gradle error: Library is not a library itself HOT 2
- Limited to minSdkVersion 15 HOT 2
- Disable/Enable widgets programmatically HOT 3
- Specify hint size when textview not empty HOT 1
- Date picker month is -1 HOT 1
- Implement setOnFocusChangeListener() for text fields HOT 1
- Use the new AppCompat widgets
- Labels not animated properly after #29
- NPE with FloatingLabelAutoCompleteTextView and AppCompat 22.1.1 on API 21+ HOT 2
- support for RTL Language HOT 4
- Different date format for JavaDateInstant HOT 4
- Is it possible to disable drawableRight for pickers? HOT 2
- Label is not floating away when setInputWidgetText() is used HOT 5
- Error in license
- Compatibility with Saaripaar Validation Library
- import to android studio
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-floatinglabel-widgets.