Когда появляется клавиатура, пользователь не может прокрутить до последних 4 элементов списка, используя вид поиска. - PullRequest
1 голос
/ 06 июля 2019

У меня есть listview с предметами и searchview в моем toolbar. Когда пользователь нажимает на значок поиска, появляется клавиатура. Есть проблема, которая сводит меня с ума. Когда появляется клавиатура, пользователь не может прокрутить до последних четырех пунктов, и да, я попробовал android:windowSoftInputMode="adjustResize" и android:windowSoftInputMode="adjustPan", но они ничего не сделали.

Manifest:

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"

    android:theme="@style/AppTheme"
    android:usesCleartextTraffic="true">
    <activity android:name=".Adapter">

    </activity>

    <activity
        android:name=".OnSwipeTouchListener"
        android:label="@string/title_activity_on_swipe_touch_listener"

        android:theme="@style/AppTheme.NoActionBar" />

    <activity
        android:name=".Activity2"
        android:screenOrientation="sensorLandscape" />
    <activity
        android:name=".MainActivity"
        android:windowSoftInputMode="adjustResize">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Activity.xml

<androidx.constraintlayout.widget.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"
    tools:context=".MainActivity">


    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />



    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="To get started please click the button below !"
        app:layout_constraintBottom_toTopOf="@+id/button"
        app:layout_constraintEnd_toEndOf="@+id/mainlistview"
        app:layout_constraintHorizontal_bias="0.533"
        app:layout_constraintStart_toStartOf="@+id/mainlistview"
        app:layout_constraintTop_toTopOf="@+id/mainlistview"
        app:layout_constraintVertical_bias="0.626" />

    <Button
        android:id="@+id/button"
        android:layout_width="123dp"
        android:layout_height="59dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:text="Open m3u"
        app:layout_constraintBottom_toBottomOf="@+id/mainlistview"
        app:layout_constraintEnd_toEndOf="@+id/mainlistview"
        app:layout_constraintStart_toStartOf="@+id/mainlistview"
        app:layout_constraintTop_toTopOf="@+id/mainlistview" />


    <ListView
        android:id="@+id/mainlistview"
        android:layout_width="match_parent"
        android:layout_height="673dp"
        android:layout_marginTop="2dp"
        android:gravity="right"
        android:textSize="2dp"
        app:layout_constraintTop_toBottomOf="@+id/toolbar"
        tools:layout_editor_absoluteX="-144dp">

    </ListView><![CDATA[



    />/>



]]>
</androidx.constraintlayout.widget.ConstraintLayout>

without keyboard

Я знаю, что есть миллиарды вопросов к этой проблеме, но буквально ничего не сработало !!! Заранее спасибо ! with keyboard and max scrolling

1 Ответ

0 голосов
/ 06 июля 2019

Обновление

Попробуйте это:

MainActivity.java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Toolbar toolbar = findViewById(R.id.main_toolbar);
        setSupportActionBar(toolbar);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        final MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.toolbar_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if(item.getItemId() == R.id.action_search) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Рез / меню / toolbar_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu>
   <item
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/action_search"
        android:icon="@android:drawable/ic_menu_search"
        app:showAsAction="always"
        app:actionViewClass="androidx.appcompat.widget.SearchView"
        android:title="@string/search"/>
</menu>

Примечание : я заполнил список из 16 элементов, используя атрибут android: records значение строки-массива (внутри звездочек внизу)

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/main_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        **android:entries="@array/dummy_items"**
        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
     />

    <com.google.android.material.appbar.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/main_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:theme="@style/Theme.AppCompat" />
    </com.google.android.material.appbar.AppBarLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

И styles.xml

 <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
 <!-- whatever customization -->

build.gradle (приложение одно)

...
dependencies {
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
}

Скриншот

Оригинальный ответ

Я бы предложил реализовать SearchDialog Activity. Он показывает всплывающее диалоговое окно для предложений и, будучи диалогом, не идет за клавиатурой.

Прочтите это официальное руководство по Android для получения дополнительной информации. https://developer.android.com/guide/topics/search/search-dialog#SearchDialog

...