Wotan2004
Wotan2004

Reputation: 1

Why is the search symbol and the text not showing in searchview in Android Studio

I am programming a simple music app in Android Studio and now I am working on the search bar. Here is my activity_main.xml code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="@color/white">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#F44336"
        android:minHeight="?attr/actionBarSize"
        android:theme="?attr/actionBarTheme">


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Musica" />

    </androidx.appcompat.widget.Toolbar>

    <androidx.appcompat.widget.SearchView
        android:id="@+id/suchfeld"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="visible">

    </androidx.appcompat.widget.SearchView>



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:id="@+id/Songbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Songs"
            android:backgroundTint="#F44336"
            android:textColor="@color/white"

            />

        <Button
            android:id="@+id/Albumbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Albums"
            android:backgroundTint="#F44336"
            android:textColor="@color/white"
            />

        <Button
            android:id="@+id/Artistbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Artists"
            android:backgroundTint="#F44336"
            android:textColor="@color/white"
            />

        <Button
            android:id="@+id/Playlistbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Playlists"
            android:backgroundTint="#F44336"
            android:textColor="@color/white"
            />

    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/buchstabeA"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="A"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutA"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeB"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="B"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutB"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeC"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="C"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutC"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />
            <TextView
                android:id="@+id/buchstabeD"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="D"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutD"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />
            <TextView
                android:id="@+id/buchstabeE"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="E"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutE"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />
            <TextView
                android:id="@+id/buchstabeF"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="F"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutF"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeG"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="G"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutG"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeH"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="H"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutH"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeI"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="I"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutI"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeJ"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="J"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutJ"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeK"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="K"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutK"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeL"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="L"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutL"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeM"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="M"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutM"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeN"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="N"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutN"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeO"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="O"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutO"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeP"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="P"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutP"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeQ"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Q"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutQ"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeR"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="R"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutR"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeS"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="S"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutS"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeT"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="T"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutT"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeU"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="U"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutU"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeV"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="V"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutV"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeW"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="W"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutW"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeX"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="X"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutX"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeY"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Y"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutY"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabeZ"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Z"
                android:textColor="@color/black"/>

            <LinearLayout
                android:id="@+id/LayoutZ"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

            <TextView
                android:id="@+id/buchstabe0"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="#"
                android:textColor="@color/black"/>

        </LinearLayout>
    </ScrollView>

</LinearLayout>

Ideally I should get this: enter image description here

But indstead the search bar symbol is not showing and when I want to type something, the text does not appear however the cursor moves to the right when I type. Also the search bar symbol is not showing. My MainActivity Class is

Test on my Oppo Phone with Android 13

No matter if I add or delete "android:visibility="visible" or change "android.widget.SearchView" to "androidx.appcompat.widget.SearchView" I get the same results.

I recently added suchfeld = findViewById(R.id.suchfeld); suchfeld.setIconifiedByDefault(false); into my MainActivity Class and at last the cursor is placed better because at the first test it was placed at the edge of the SearchView Bar and now it is placed more to the right. : When I change the background colour to black (8th command in activity_main.xml) the symbol however appears and the text is visible. This is my MainActivity Class:

package com.example.musica;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toolbar;

import java.io.File;
import java.util.Arrays;

public class MainActivity extends Activity implements View.OnClickListener {

    Button Songbutton, Albumbutton, Artistbutton, Playlistbutton;
    Toolbar suche;
    //TextView buchstabeA,buchstabeB, buchstabeC,buchstabeD,buchstabeE,buchstabeA,buchstabeA,buchstabeA,buchstabeA,buchstabeA,buchstabeA,buchstabeA,buchstabeA,buchstabeA,buchstabeA,buchstabeA,
    LinearLayout layoutA, layoutB, layoutC, layoutD, layoutE, layoutF, layoutG, layoutH, layoutI, layoutJ, layoutK, layoutL, layoutM, layoutN, layoutO, layoutP, layoutQ, layoutR, layoutS, layoutT, layoutU, layoutV, layoutW, layoutX, layoutY, layoutZ, layout0;
    LinearLayout[] layoutList = {layoutA, layoutB, layoutC, layoutD, layoutE, layoutF, layoutG, layoutH, layoutI, layoutJ, layoutK, layoutL, layoutM, layoutN, layoutO, layoutP, layoutQ, layoutR, layoutS, layoutT, layoutU, layoutV, layoutW, layoutX, layoutY, layoutZ, layout0};
    SearchView suchfeld;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        suchfeld = findViewById(R.id.suchfeld);
        suchfeld.setIconifiedByDefault(false);

        
        



    }

    @Override
    public void onClick(View view){

    }


}

This is my manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <application

        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Musica"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
        </activity>
    </application>

</manifest>

Upvotes: 0

Views: 34

Answers (0)

Related Questions