在我的Fragment
SearchView
ConstraintLayout
中<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.SearchView
android:id="@+id/searchView"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/search_view_bg"
android:theme="@style/SearchViewTheme"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:searchHintIcon="@null" />
</android.support.constraint.ConstraintLayout>
。
的xml:
ViewCompat.setLayoutDirection(view.findViewById(R.id.searchView), ViewCompat.LAYOUT_DIRECTION_RTL);
以下是我在右边框上设置图标的方法
@PropertySource
结果如下:
行。它适用于 Android 4.3 +
但如果我从 Android 4.0 开始,那么我会得到下一个结果:
如您所见,右侧没有显示图标。
如何将图标移到右侧?
答案 0 :(得分:0)
尝试将重力设置为布局参数。
LinearLayout.LayoutParams params =
(LinearLayout.LayoutParams) searchview.getLayoutParams();
params.gravity = Gravity.RIGHT;
searchView.setLayoutParams(params);