android - 没有viewpager的自定义Tablayout隐藏了textview

标签 android xml android-layout layout android-tablayout

因此,我有一个带有文本和下方圆形黑点的自定义标签布局,以向用户表明他们需要单击它。所以,我的 tablayout 没有任何 viewpager。我尝试了 notification badger,但它在 tablayout 中不起作用。

主类.java

public class MainActivity extends AppCompatActivity {

        TabLayout tabLayout;

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

        View view = (FrameLayout)LayoutInflater.from(this).inflate(R.layout.custom_layout, null);
        TextView tv = (TextView) view.findViewById(R.id.textview);
        tv.setText("This is cool");


        tabLayout.addTab(tabLayout.newTab().setCustomView(view));



    }
}

cusotm_layout.xml

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
     android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:id="@+id/textview"
        android:text="SOmetext "

        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimaryDark"
        android:layout_gravity="center" />

    <ImageView
        android:layout_width="100dp"
        android:src="@drawable/bg_card_elements"
        android:id="@+id/imageview"
        android:layout_gravity="bottom|center"
        android:layout_height="100dp">

    </ImageView>

</FrameLayout>

我不知道为什么我的文字不可见。任何想法? image without text

最佳答案

你的 textview 隐藏在 imageview 后面,所以它没有显示。

像这样切换imageview和textview

cusotm_layout.xml

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

<ImageView
        android:layout_width="100dp"
        android:src="@drawable/bg_card_elements"
        android:id="@+id/imageview"
        android:layout_gravity="bottom|center"
        android:layout_height="100dp">

</ImageView>

<TextView
        android:layout_width="wrap_content"
        android:id="@+id/textview"
        android:text="SOmetext "
        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimaryDark"
        android:layout_gravity="center" /></FrameLayout>

关于android - 没有viewpager的自定义Tablayout隐藏了textview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58092826/

相关文章:

android - 在 Android 中获取首选屏幕亮度

Android 谷歌驱动器休息 API : skip consent screen (hardcoded account)

java - 如何从 Android 中的应用程序访问我的相机

xml - Delphi XML (MSXML) 例程的二次运行时

android - 使用最大数量的共享首选项

android - Retrofit 2.0 发布请求

java - 致命异常: AsyncTask #1, android远程数据库注册

c# - 查找并删除所有以 x 开头的字符串

android - 具有 GridLayoutManager 的 RecyclerView 和具有不同 viewHolder 的第一个元素

android - 下拉微调器仅加载列表中的第一项,然后在按下时返回 NullPointerException