[ios]代码库
//本方法importModule
//main方法
public class MainActivity extends FragmentActivity implements View.OnClickListener{
private SlidingPaneLayout slidingpan;
private LinearLayout full_left;
private ListView lv;
private List<String> list;
private TextView one;
private TextView two;
private TextView three;
private TextView four;
private TextView[] textArray;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// configure the SlidingMenu
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
// 设置触摸屏幕的模式
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.color.colorAccent);
// 设置滑动菜单视图的宽度
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
// 设置渐入渐出效果的值
menu.setFadeDegree(0.35f);
/**
* SLIDING_WINDOW will include the Title/ActionBar in the content
* section of the SlidingMenu, while SLIDING_CONTENT does not.
*/
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
//为侧滑菜单设置布局
menu.setMenu(R.layout.dibu_layout);
one = (TextView) findViewById(R.id.one);
one.setOnClickListener(this);
two = (TextView) findViewById(R.id.two);
two.setOnClickListener(this);
three = (TextView) findViewById(R.id.three);
three.setOnClickListener(this);
four = (TextView) findViewById(R.id.four);
four.setOnClickListener(this);
textArray = new TextView[]{one,two};
// initData();
setC(0);
addFragment(new OneFragment());
}
public void addFragment(Fragment f){
FragmentManager manager=getSupportFragmentManager();
FragmentTransaction transaction=manager.beginTransaction();
transaction.replace(R.id.frame,f);
transaction.commit();
}
public void setC(int index){
for(int i=0;i<textArray.length;i++){
if(i==index){
textArray[i].setTextColor(Color.RED);
}else{
textArray[i].setTextColor(Color.BLACK);
}
}
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.one:
addFragment(new OneFragment());
setC(0);
break;
case R.id.two:
addFragment(new TwoFragment());
setC(1);
break;
}
}
}
<dimen name="slidingmenu_offset">260dp</dimen>
<dimen name="shadow_width">15dp</dimen>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frame"></FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/one"
android:text="第一页"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/two"
android:text="第二页"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/three"
android:text="第三页"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/four"
android:text="第四页"/>
by: 发表于:2017-10-13 10:10:45 顶(0) | 踩(0) 回复
??
回复评论