我想用带有TabLayout
的点来显示我的viewPager页面。但是tablayout没有显示任何内容。
我的java代码:
public class MainActivity extends AppCompatActivity {
private ViewPager viewPager;
private ViewPagerAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//adapter + view pager
adapter = new ViewPagerAdapter(getSupportFragmentManager());
viewPager = (ViewPager) findViewById(R.id.container);
viewPager.setAdapter(adapter);
viewPager.setOnPageChangeListener(this);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_dots);
tabLayout.setupWithViewPager(viewPager,true);
}
我的xml代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/lib/com.app.chasebank" android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/main_color"
tools:context="zekrshomargouya.maxsoft.com.zekrshomargouya.MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:navigationIcon="?attr/homeAsUpIndicator"
style="@style/toolbar">
</android.support.v7.widget.Toolbar>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_marginBottom="50dp"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp"
android:layout_marginTop="30dp"
android:layout_gravity="top"
android:layout_below="@id/toolbar"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_dots"
android:layout_width="match_parent"
android:layout_height="40dp"
app:tabBackground="@drawable/tab_selector"
app:tabGravity="center"
app:tabIndicatorHeight="2dp"
android:background="#ff55ff"
android:layout_marginTop="0dp"
android:layout_gravity="center"
android:layout_alignParentBottom="true"/>
我的点代码:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/tab_indicator_seleced"
android:state_selected="true"/>
<item android:drawable="@drawable/tab_indicator_default"/>
和
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:innerRadius="0dp"
android:shape="ring"
android:thickness="10dp"
android:useLevel="false">
<solid android:color="@color/colorAccent"/>
</shape>
</item>
我的build.gradle代码:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:support-v4:25.0.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.0.1'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
答案 0 :(得分:0)
在这种情况下,您应该键入组件的属性,而不是复制/粘贴。所以app
替换为app1
。就这样!
<android.support.design.widget.TabLayout
android:id="@+id/tab_dots"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:tabIndicatorHeight="0dp"
app1:tabBackground="@drawable/tab_selector"
app1:tabGravity="center"/>