我做了一些欺騙。這是醜陋的,但爲我工作。您可以使用一個按鈕(作爲佔位符)與0dp高度和。庫使用anchorview僅查找彈出窗口的位置。 看看我下面如何。
這是XML
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true"
app:hintTextAppearance="@style/TextInput">
<android.support.design.widget.TextInputEditText
android:id="@+id/et_pn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username_pn"
android:inputType="number"
android:maxLength="18"
android:drawableEnd="@drawable/ic_close"
app:theme="@style/EditText"/>
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/placeholder"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="15dp"
android:layout_centerVertical="true"/>
</RelativeLayout>
這是怎麼點擊按鈕繪製的應用。
TextInputEditText button;
private Button placeholder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (TextInputEditText) findViewById(R.id.et_pn);
placeholder = (Button) findViewById(R.id.placeholder);
button.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_LEFT = 0;
final int DRAWABLE_TOP = 1;
final int DRAWABLE_RIGHT = 2;
final int DRAWABLE_BOTTOM = 3;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (event.getRawX() >= (button.getRight() - button.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
Tooltip.Builder builder = new Tooltip.Builder(MainActivity.this, placeholder)
.setCancelable(true)
.setDismissOnClick(true)
.setCornerRadius(20f)
.setGravity(Gravity.BOTTOM)
.setText(R.string.tooltip_hello_world);
builder.show();
return false;
}
}
return false;
}
});
}
不完全是,我已經嘗試過這種方法,但是當我需要從改變佈局的方向出現問題,左到右右到左,因爲我在應用程序中英文使用兩種語言和希伯來語...所以,如果你可以做同樣的事情,但與LinnearLayout它會好起來 –
試試這個https://android-developers.googleblog.com/2013/03/native-rtl-support-in- android-42.html 基本上,這是在您將語言環境更改爲RTL語言時的佈局鏡像。 –