我们通过读代码发现,数据库写 操作是在欢迎界面里面设置的,那么我们先实现欢迎界面。
为了更好的复制代码,我们先实现一些简单的Helper类。
首先是设置字体的,这个很简单。
//Caches the custom fonts in memory to improve rendering performance.
public class TypefaceHelper {
public static final String TYPEFACE_FOLDER = "fonts";
public static final String TYPEFACE_EXTENSION = ".ttf";
private static Hashtable<String, Typeface> sTypeFaces = new Hashtable<String, Typeface>(4);
public static Typeface getTypeface(Context context, String fileName) {
Typeface tempTypeface = sTypeFaces.get(fileName);
if (tempTypeface==null) {
String fontPath = new StringBuilder(TYPEFACE_FOLDER).append('/')
.append(fileName)
.append(TYPEFACE_EXTENSION)
.toString();
tempTypeface = Typeface.createFromAsset(context.getAssets(), fontPath);
sTypeFaces.put(fileName, tempTypeface);
}
return tempTypeface;
}
}
现在开始实现WelcomActivity类。由于欢迎界面是用Fragment呈现的,我们用Fragment来管理。
public class WelcomeActivity extends AppCompatActivity {
private Context mContext;
private Common mApp;
private ViewPager welcomeViewPager;
// private LinePageIndicator indicator;
private String mAccountName;
// private MusicFoldersFragment mMusicFoldersFragment;
// public static BuildingLibraryProgressFragment mBuildingLibraryProgressFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
mApp = (Common) this.getApplicationContext();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
setContentView(R.layout.activity_welcome);
setTheme(R.style.AppTheme);
if (getActionBar()!=null)
getActionBar().hide();
welcomeViewPager = (ViewPager) findViewById(R.id.welcome_pager);
FragmentManager fm = getSupportFragmentManager();
welcomeViewPager.setAdapter(new WelcomePagerAdapter(fm));
welcomeViewPager.setOffscreenPageLimit(6);
}
class WelcomePagerAdapter extends FragmentStatePagerAdapter{
public WelcomePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return new WelcomeFragment();
}
@Override
public int getCount() {
return 1;
}
}
}
第一个界面搞定了。
下面在添加一个Fragment
/**
* Created by kankan on 2016/5/26.
*/
public class MusicFoldersFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_welcome_screen_2, container, false);
return view;
}
}
在修改一下Adapter。这样结果如图