简体   繁体   English

我找不到 ViewPager2 的 AppCompatTextView(捕获屏幕)

[英]I can't find AppCompatTextView of ViewPager2(Capture Screen)

problem:问题:

Problem问题


if I fix:如果我修复:

After


I want to see AppCompatTextView with Android-Studio.我想查看带有 Android-Studio 的AppCompatTextView
How to see the AppCompatTextView ?如何查看AppCompatTextView
Nothing Error.没有错误。 I don't know why..我不知道为什么。。
Please help this problem..请帮忙解决这个问题。。



activity_searchresult.xml:活动搜索结果.xml:

<?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/cfb"
    tools:context=".ResultActivity">

    <FrameLayout
        android:id="@+id/content_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="600dp"
            android:background="@color/cfb"
            tools:context=".ResultActivity">

            <TextView
                android:id="@+id/resultText1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/result_text1"
                android:textColor="@color/black"
                android:textSize="23sp"
                android:layout_marginLeft="30dp"
                app:layout_constraintBottom_toTopOf="@+id/resultText2"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent" />
            <TextView
                android:id="@+id/resultText2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/result_text2"
                android:textColor="@color/black"
                android:textSize="23sp"
                android:layout_marginBottom="30dp"
                app:layout_constraintBottom_toTopOf="@+id/resultViewPager2"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent" />


            <ImageButton
                android:id="@+id/resultFilterButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="0dp"
                android:layout_marginBottom="10dp"
                android:layout_marginEnd="15dp"
                android:layout_marginRight="28dp"
                android:background="@color/cfb"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintBottom_toBottomOf="@+id/dots_indicator"
                app:srcCompat="@drawable/filter" />

            <TextView
                android:id="@+id/filterText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="25dp"
                android:layout_marginRight="40dp"
                android:text="@string/filter"
                android:textColor="#000000"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/resultFilterButton" />

            <androidx.viewpager2.widget.ViewPager2
                android:id="@+id/resultViewPager2"
                android:layout_width="270dp"
                android:layout_height="270dp"
                android:layout_marginBottom="190dp"
                android:orientation="horizontal"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintVertical_bias="0.3" />

            <com.tbuonomo.viewpagerdotsindicator.DotsIndicator
                android:id="@+id/dots_indicator"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="110dp"
                app:dotsColor="@color/white"
                app:dotsCornerRadius="8dp"
                app:dotsSize="14dp"
                app:dotsSpacing="4dp"
                app:dotsWidthFactor="2.5"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.498"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/resultViewPager2"
                app:layout_constraintBottom_toBottomOf="parent"
                app:progressMode="true"
                app:selectedDotColor="@color/black" />
            <ImageView
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_marginStart="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginBottom="30dp"
                app:layout_constraintBottom_toTopOf="@+id/resultViewPager2"
                app:srcCompat="@drawable/cafebot" />
        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".ResultActivity">
            <FrameLayout
                android:id="@+id/frameLayout"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                app:layout_constraintBottom_toTopOf="@id/navigationView"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent"/>

            <com.google.android.material.bottomnavigation.BottomNavigationView
                android:id="@+id/navigationView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?android:attr/windowBackground"
                app:itemTextColor="@drawable/bottom_icon_color"
                app:itemIconTint="@drawable/bottom_icon_color"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="parent"
                app:menu="@menu/bottom_nav" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </FrameLayout>

</LinearLayout>


result_item_viewpager.xml: result_item_viewpager.xml:

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/result_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/result_menu_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:textColor="@android:color/black"
        android:textSize="26sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/result_sample_image" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/result_cafe_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:textColor="@android:color/black"
        android:textStyle="bold"
        android:textSize="23sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/result_menu_name" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/result_product_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:textColor="@android:color/black"
        android:textSize="22sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/result_cafe_name" />

    <ImageView
        android:id="@+id/result_sample_image"
        android:layout_width="270dp"
        android:layout_height="270dp"
        android:layout_marginTop="4dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:srcCompat="@tools:sample/avatars" />

</androidx.constraintlayout.widget.ConstraintLayout>

ResultDataPage.java:结果数据页.java:

package com.example.myapplication;

public class ResultDataPage {
    int resultImage;
    String resultCafeName;
    String resultMenuName;
    int resultPrice;

    public ResultDataPage(int image, String menuName, String cafeName, int price){
        this.resultImage = image;
        this.resultMenuName = menuName;
        this.resultCafeName = cafeName;
        this.resultPrice = price;
    }

    public int getImage(){
        return resultImage;
    }

    public void setImage(int image) {
        this.resultImage = image;
    }

    public String getMenuName(){
        return resultMenuName;
    }

    public void setMenuName(String menuName) {
        this.resultMenuName = menuName;
    }

    public String getCafeName() {
        return resultCafeName;
    }

    public void setCafeName(String cafeName) {
        this.resultCafeName = cafeName;
    }

    public int getPrice(){
        return resultPrice;
    }

    public void setPrice(int price){
        this.resultPrice = price;
    }
}


ResultViewPagerAdapter.java: ResultViewPagerAdapter.java:

package com.example.myapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class ResultViewPagerAdapter extends RecyclerView.Adapter<ResultViewHolderPage> {

    private ArrayList<ResultDataPage> listData;

    ResultViewPagerAdapter(ArrayList<ResultDataPage> data) {
        this.listData = data;
    }

    @Override
    public ResultViewHolderPage onCreateViewHolder(ViewGroup parent, int viewType) {
        Context context = parent.getContext();
        View view = LayoutInflater.from(context).inflate(R.layout.result_item_viewpager, parent, false);
        return new ResultViewHolderPage(view);
    }

    @Override
    public void onBindViewHolder(ResultViewHolderPage holder, int position) {
        if(holder instanceof ResultViewHolderPage){
            ResultViewHolderPage viewHolder = (ResultViewHolderPage) holder;
            viewHolder.onBind(listData.get(position));
        }
    }

    @Override
    public int getItemCount() {
        return listData.size();
    }
}


ResultViewHolderPage.java: ResultViewHolderPage.java:

package com.example.myapplication;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

public class ResultViewHolderPage extends RecyclerView.ViewHolder {
    
    private ImageView resultImage;
    private TextView resultCafeName;
    private TextView resultMenuName;
    private TextView resultPrice;

    ResultDataPage resultData;

    ResultViewHolderPage(View itemView) {
        super(itemView);
        resultCafeName = itemView.findViewById(R.id.result_cafe_name);
        resultImage = itemView.findViewById(R.id.result_sample_image);
        resultPrice = itemView.findViewById(R.id.result_product_price);
        resultMenuName = itemView.findViewById(R.id.result_menu_name);
    }

    public void onBind(ResultDataPage resultData){
        this.resultData = resultData;

        resultMenuName.setText(resultData.getMenuName());
        resultCafeName.setText(resultData.getCafeName());
        resultImage.setImageResource(resultData.getImage());
        resultPrice.setText(Integer.toString(resultData.getPrice()).concat("원"));
    }
}

ResultActivity.java:结果Activity.java:

package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.tbuonomo.viewpagerdotsindicator.DotsIndicator;

import java.util.ArrayList;

public class ResultActivity extends AppCompatActivity {
    // 가운데
    private ViewPager2 result_ViewPager2;
    private DotsIndicator dotsIndicator;
    private ArrayList<ResultDataPage> list;

    // 바텀네비게이션뷰
    private BottomNavigationView bottomNav;
    private FragmentManager fragmentManager = getSupportFragmentManager();
    private SearchPage fragmentSearch = new SearchPage();
    private HomePage fragmentHome = new HomePage();
    private CafePage fragmentCafe = new CafePage();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_searchresult);

        this.viewpage(); // 뷰페이저 (메뉴검색결과값)

        // 바텀네비게이션
        bottomNav = findViewById(R.id.navigationView);
        bottomNav.setOnNavigationItemSelectedListener(new ResultActivity.ItemSelectedListener());
    }

    private void viewpage(){
        list = new ArrayList<>();
        list.add(new ResultDataPage(R.drawable.sample_1, "아메리카노","스타벅스", 4900));
        list.add(new ResultDataPage(R.drawable.sample_2, "아메리카노","투썸플레이스", 4100));
        list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","이디야커피", 3000));
        list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));
        list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));
        list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));
        list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));
        list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));
        list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));
        list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));

        result_ViewPager2 = findViewById(R.id.resultViewPager2);
        result_ViewPager2.setAdapter(new ResultViewPagerAdapter(list));

        dotsIndicator = findViewById(R.id.dots_indicator);
        dotsIndicator.setViewPager2(result_ViewPager2);
    }

    //바텀네비
    class ItemSelectedListener implements BottomNavigationView.OnNavigationItemSelectedListener {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
            FragmentTransaction transaction = fragmentManager.beginTransaction();

            switch (menuItem.getItemId()) {
                case R.id.searchItem:
                    Intent intent1 = new Intent(getApplicationContext(), com.example.myapplication.SearchActivity.class);
                    startActivity(intent1);
                    //transaction.replace(R.id.frameLayout, fragmentSearch).commitAllowingStateLoss();
                    break;
                case R.id.homeItem:
                    Intent intent2 = new Intent(getApplicationContext(), com.example.myapplication.MainActivity.class);
                    startActivity(intent2);
                    //transaction.replace(R.id.frameLayout, fragmentHome).commitAllowingStateLoss();
                    break;
                case R.id.cafeItem:
                    Intent intent3 = new Intent(getApplicationContext(), com.example.myapplication.MainCflistActivity.class);
                    startActivity(intent3);
                    //transaction.replace(R.id.frameLayout, fragmentCafe).commitAllowingStateLoss();
                    break;
            }
            return true;
        }
    }

}

UPDATE : (Comments below for details) At the end, text was hidden because the ViewPager was too small.更新:(详情如下评论)最后,文本被隐藏,因为 ViewPager 太小了。

The AppCompatTextView is a retro-compatible text view for old Support Library support. AppCompatTextView 是旧支持库支持的复古兼容文本视图。 Which is your minimum supported SDK version?您支持的最低 SDK 版本是哪个? You don't need this if you are using AndroidX.如果您使用的是 AndroidX,则不需要这个。

However, it comes with this dependecy you have to put in your module build.gradle file:但是,它带有这种依赖关系,您必须将其放入模块 build.gradle 文件中:

implementation 'com.android.support:appcompat-v7:28.0.0'

After this, sync Gradle and you can use the "AppCompatTextView":在此之后,同步 Gradle 并且您可以使用“AppCompatTextView”:

在此处输入图像描述

References: https://developer.android.com/topic/libraries/support-library/packages#v7 https://developer.android.com/topic/libraries/support-library/setup#choosing https://developer.android.com/reference/androidx/appcompat/widget/AppCompatTextView References: https://developer.android.com/topic/libraries/support-library/packages#v7 https://developer.android.com/topic/libraries/support-library/setup#choosing https://developer. android.com/reference/androidx/appcompat/widget/AppCompatTextView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM