Closed isaacfi closed 6 years ago
@isaacfi - I think you'd have to look at styling options for the android TextInputLayout
documentation to know what all you can control on the floating label. You're likely needing to use the hintTextAppearance
attribute and XML styles as documented in the README.
Questions like this really should go on Stack Overflow - github issues are more for bug reports. 😄 Odds are, there's someone that's already ran into this and knows exactly how to style that hint text.
This is an issue, the problem is that hintTextApperance style cannot add margin because it is a TextAppearance Style. I implemented the lineHeight property for android in your plugin after reading this stackoverflow answer: TextInputLayout :How to give padding or margin to hint?
I share you the android code:
export const lineHeightProperty = new Property<TextInputLayout, number>({
name: "lineHeight",
affectsLayout: true,
valueConverter: v => parseFloat(v)
});
private setupTextView() {
if (!this.isLoaded) {
return;
}
const textField = this._textField;
const nativeView = this.nativeView;
const layoutParams = new (<any>android).widget.LinearLayout.LayoutParams(
(<any>android).widget.LinearLayout.LayoutParams.MATCH_PARENT,
(<any>android).widget.LinearLayout.LayoutParams.WRAP_CONTENT);
const current = nativeView.getEditText();
const nativeTextField = textField.nativeView;
if (current !== nativeTextField) {
if (current) {
nativeView.removeView(current);
}
if (this.lineHeight) {
var paddingView = new (<any>android).view.View(this._context);
const layoutParamsPaddingView = new (<any>android).widget.LinearLayout.LayoutParams(
(<any>android).widget.LinearLayout.LayoutParams.MATCH_PARENT,
this.lineHeight);
nativeView.addView(paddingView, 0, layoutParamsPaddingView);
}
nativeView.addView(nativeTextField, 0, layoutParams);
}
// sometimes hint text isn't immediately triggered to move when navigating back to a prior view.
// this triggers it via brute force :(
const txtValue = textField.nativeView.getText();
nativeTextField.setText('');
nativeTextField.setText(txtValue);
}
[lineHeightProperty.setNative](value: number) {
if (!isNaN(value)) {
this.lineHeight = value;
}
}
exports.lineHeightProperty.register(TextInputLayout);
textInputLayout.android.ts.zip
Regards
While this may be an issue in the broader sense of the word, the aim of this component is simply parity with the native TextInputLayout
component. I don't feel that doing this adding of a spacer block (the padding view) is appropriate in this level, so I'm not ready to call this an issue within the realm of this repo at this time.
What about other answers (i.e. the accepted answer) in that same thread that says that the paddingTop
style on the EditText
element works to accomplish this same thing? The solution you went with is near the bottom, has almost no votes, and isn't the accepted answer for the issue at hand - not sure why that one was picked over the established/accepted solution.. does the accepted one no longer work or something?
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/floating_hint_margin"
android:background="@drawable/bg_edit_text" />
</android.support.design.widget.TextInputLayout>
I've tested the other ones, but they depends on configuration and the padding top size would be static. Test the solution that I shared you.
Cheers
Im currently ussing the TextField for android with class="input input-rounded" but I need margin between this items. Is it prossible?