我有ViewPager,它包含四个布局(彼此相同:ImageView和两个TextViews控件):
view_pager = (ViewPager) findViewById(R.id.view_pager);
layouts = new int[] {
R.layout.activity_screen_walk_1,
R.layout.activity_screen_walk_2,
R.layout.activity_screen_walk_3,
R.layout.activity_screen_walk_4
};
viewPageAdapter = new ViewPageAdapter();
view_pager.setAdapter(viewPageAdapter);
view_pager.addOnPageChangeListener(viewPagerPageChangeListener);
这段代码没问题 - 显示查看寻呼机并且工作正常。但我希望在视图寻呼机的布局中的所有文本视图中更改字体。
Typeface myFontBold = Typeface.createFromAsset(getAssets(), "fonts/Oswald-Bold.ttf");
for (int count=0; count < view_pager.getChildCount(); count++){
Toast.makeText(MainActivity.this, "ppp", Toast.LENGTH_SHORT).show();
View view = view_pager.getChildAt(count);
if(view instanceof TextView){
((TextView)view).setTypeface(myFontBold);
}
}
但这不起作用...... 请帮帮我。 问候 马尔钦
答案 0 :(得分:0)
此处,View view = view_pager.getChildAt(count);
返回的视图是您的整个布局。
所以,试试这个来设置TextView的字体:
TextView tv = (TextView) view.findViewById(R.id.<your TextView ID>);
tv.setTypeface(myFontBold);