谷粒学院视频:
http://www.gulixueyuan.com/my/course/134/summary
http://www.gulixueyuan.com/course/explore/android?subCategory=AndroidCuttingEdge
1.图标check点击:
android:drawableTop="@drawable/rb_common_frame_drawable_selector"
rb_common_frame_drawable_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="@drawable/ic_tab_video"/>
<item android:state_checked="true" android:drawable="@drawable/ic_tab_video_press"/>
</selector>
2.文字check点击:
<item name="android:textColor">@drawable/bottom_textcolor_drawable_selector</item>
bottom_textcolor_drawable_selector.xml:<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:color="#363636"/>
<item android:state_checked="true" android:color="#3097FD"/>
</selector>
3.xml中相同的部分使用style:
<RadioButton
android:id="@+id/rb_common_frame"
style="@style/bottom_tag_style"
android:drawableTop="@drawable/rb_common_frame_drawable_selector"
android:text="常用框架" />
<RadioButton
android:id="@+id/rb_thirdparty"
style="@style/bottom_tag_style"
android:drawableTop="@drawable/rb_thirdparty_drawable_selector"
android:text="第三方" />
style:
<style name="bottom_tag_style">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:button">@android:color/transparent</item>
<item name="android:drawablePadding">3dp</item>
<item name="android:gravity">center</item>
<item name="android:textColor">@drawable/bottom_textcolor_drawable_selector</item>
<item name="android:textSize">10sp</item>
</style>
4.Alt+Shift+M : 代码--->方法
5. Fragment基类:BaseFragment
package com.venusjj.base;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by Administrator on 2018/5/24.
*/
public abstract class BaseFragment extends Fragment {
protected Context mContext;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext=getActivity();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return initView();
}
protected abstract View initView();
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
initData();
}
protected void initData(){
}
}
6.防止fragment横竖屏切换,导致重复加载:
android:configChanges="orientation|screenSize|keyboardHidden"
7.获取当前的fragment:
private BaseFragment getFragment() {
BaseFragment fragment=mBaseFragment.get(position);
return fragment;
}
8.显示当前的fragment,防止重复加载;
/**
* 性能优化
* @param from
* @param to
*/
private void switchFrament(Fragment from, Fragment to) {
if(from!=to){
mContent=to;
FragmentTransaction ft=getSupportFragmentManager().beginTransaction();
if(!to.isAdded()){
if(from!=null){
ft.hide(from);
}
if(to!=null){
ft.add(R.id.fl_content,to).commit();
}
}else{
if(from!=null){
ft.hide(from);
}
if(to!=null){
ft.show(to).commit();
}
}
}
}
9.