因此,我有一个带有文本和下方圆形黑点的自定义标签布局,以向用户表明他们需要单击它。所以,我的 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>
最佳答案
你的 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/