A custom TextView which shows placeholder lines given a sample text when it has no text set
You give it some sample text, it calculates and draws equivalent placeholder lines. You then give it some text (.setText(...)
), it automatically gets rid of the placeholder and shows your text.
compile 'app.youkai.placeholdertextview:library:1.1.1'
Note: You might have to add jcenter()
to your repositories.
<app.youkai.placeholdertextview.PlaceholderTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/my_text_color"
android:lines="2"
android:maxLines="3"
app:ptv_placeholderColor="@color/my_placeholder_color"
app:ptv_sampleText="Lorem ipsum dolor sit amet" />
placeholderTextView.setSampleText("Lorem ipsum dolor sit amet");
int originalPlaceholderColor = placeholderTextView.getPlaceholderColor();
placeholderTextView.setPlaceholderColor(getColor(R.colod.my_placeholder.color));
Yes, PlaceholderTextView does respect android:lines
and android:maxLines
attributes when displaying the placeholder lines.
By default, PlaceholderTextView uses the text color with 20% alpha. You can use app:ptv_placeholderColor="@color/...
or ptv.setPlaceholdercolor(int)
to set your own color.
Copyright (C) 2017 The Youkai Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Apache License Version 2.0 (LICENSE)