刷卡次数+标题地带 - 更改标题名 [英] Swipe Views + Title Strip - change title name
问题描述
使用导航的BlankActivity模板
类型:刷卡次数+标题地带
选择创建一个具有三个片段部分的应用程序,一个紧凑的标题条标题(称为滚动标签Android的设计指南)和部分之间滑动导航的基础上,刷卡视图设计模式。
凭什么我改一下标题条默认其section1,2,3说我要重命名的章节任何想法如何?
MainActivity.java
包twh.reviser.root;进口java.util.Locale中;
进口android.os.Bundle;
进口android.support.v4.app.Fragment;
进口android.support.v4.app.FragmentActivity;
进口android.support.v4.app.FragmentManager;
进口android.support.v4.app.FragmentPagerAdapter;
进口android.support.v4.app.NavUtils;
进口android.support.v4.view.ViewPager;
进口android.view.Gravity;
进口android.view.LayoutInflater;
进口android.view.Menu;
进口android.view.MenuItem;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.TextView;公共类MainActivity扩展FragmentActivity {/ **
*本{@link android.support.v4.view.PagerAdapter},将提供
*对于每个部分的片段。我们使用
* {@link android.support.v4.app.FragmentPagerAdapter}衍生物,其
*将让每一个片段加载在内存中。如果这成为太内存
*密集,它可能是最好切换到
* {@link android.support.v4.app.FragmentStatePagerAdapter}。
* /
SectionsPagerAdapter mSectionsPagerAdapter;/ **
*本{@link ViewPager}将承载部分内容。
* /
ViewPager mViewPager;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
//创建将返回一个片段为三个的适配器
//应用的主要部分。
mSectionsPagerAdapter =新SectionsPagerAdapter(getSupportFragmentManager()); //设置的ViewPager与部分适配器。
mViewPager =(ViewPager)findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);}@覆盖
公共布尔onCreateOptionsMenu(菜单菜单){
//充气菜单;如果是present这增加了项目操作栏。
。getMenuInflater()膨胀(R.menu.main,菜单);
返回true;
}/ **
* A {@link FragmentPagerAdapter}返回对应片段
*章节/标签/页面。
* /
公共类SectionsPagerAdapter扩展FragmentPagerAdapter { 公共SectionsPagerAdapter(FragmentManager FM){
超(FM);
} @覆盖
公共片段的getItem(INT位置){
//的getItem被称为实例化片段为给定的页面。
//返回一个DummySectionFragment(定义为静态内部类
//下面)附页码为它的独立参数。
片段片段=新DummySectionFragment();
捆绑ARGS =新包();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER,位置+ 1);
fragment.setArguments(参数);
返回片段;
} @覆盖
公众诠释的getCount(){
//显示3总页数。
返回3;
} @覆盖
公共CharSequence的getPageTitle(INT位置){
区域设置L = Locale.getDefault();
开关(位置){
情况下0:
返回的getString(R.string.title_section1).toUpperCase(升);
情况1:
返回的getString(R.string.title_section2).toUpperCase(升);
案例2:
返回的getString(R.string.title_section3).toUpperCase(升);
}
返回null;
}
}/ **
*一个虚拟片段重新presenting应用程序的一部分,但只是
*显示虚拟文本。
* /
公共静态类DummySectionFragment扩展片段{
/ **
*片段参数重新presenting本节号
*片段。
* /
公共静态最后弦乐ARG_SECTION_NUMBER =SECTION_NUMBER; 公共DummySectionFragment(){
} @覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
捆绑savedInstanceState){
查看rootView = inflater.inflate(R.layout.fragment_main_dummy,集装箱,FALSE);
TextView的dummyTextView =(TextView中)rootView.findViewById(R.id.section_label);
dummyTextView.setText(Integer.toString(getArguments()调用getInt(ARG_SECTION_NUMBER)));
返回rootView;
}
}}
fragment_main_dummy.xml
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:paddingBottom会=@扪/ activity_vertical_margin
机器人:paddingLeft =@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:paddingTop =@扪/ activity_vertical_margin
工具:上下文=$ MainActivity DummySectionFragment。><的TextView
机器人:ID =@ + ID / section_label
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/>< / RelativeLayout的>
activity_main.xml中
< android.support.v4.view.ViewPager的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:ID =@ + ID /寻呼机
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@绘制/ app_bg
工具:上下文=MainActivity。><! -
这个标题条会显示当前可见的页面标题,以及网页
标题相邻的页面。
- >< android.support.v4.view.PagerTitleStrip
机器人:ID =@ + ID / pager_title_strip
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =顶
机器人:背景=#5757FF
机器人:paddingBottom会=4DP
机器人:paddingTop =4DP
机器人:文字颜色=#FFF/>< /android.support.v4.view.ViewPager>
在你的 SectionsPagerAdapter
,修改 getPageTitle(INT位置)
来获取页面标题为相应的页面。
The BlankActivity template with the Navigation Type: Swipe Views + Title Strip option creates an application with three Fragment sections, a compact title strip header (known as Scrollable Tabs in the Android Design guide) and swipe navigation between the sections, based on the swipe view design pattern.
so how can i change what the title strip says for default its section1,2,3 i want to rename the sections any ideas how?
MainActivity.java
package twh.reviser.root;
import java.util.Locale;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.NavUtils;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class MainActivity extends FragmentActivity {
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link android.support.v4.app.FragmentPagerAdapter} derivative, which
* will keep every loaded fragment in memory. If this becomes too memory
* intensive, it may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_section1).toUpperCase(l);
case 1:
return getString(R.string.title_section2).toUpperCase(l);
case 2:
return getString(R.string.title_section3).toUpperCase(l);
}
return null;
}
}
/**
* A dummy fragment representing a section of the app, but that simply
* displays dummy text.
*/
public static class DummySectionFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main_dummy, container, false);
TextView dummyTextView = (TextView) rootView.findViewById(R.id.section_label);
dummyTextView.setText(Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER)));
return rootView;
}
}
}
fragment_main_dummy.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity$DummySectionFragment" >
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
activity_main.xml
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/app_bg"
tools:context=".MainActivity" >
<!--
This title strip will display the currently visible page title, as well as the page
titles for adjacent pages.
-->
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#5757FF"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textColor="#fff" />
</android.support.v4.view.ViewPager>
In your SectionsPagerAdapter
, change the getPageTitle(int position)
to get the page titles for the corresponding pages.
这篇关于刷卡次数+标题地带 - 更改标题名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!