增加抽屉菜单
This commit is contained in:
parent
b23410c54b
commit
798b0228d8
|
@ -362,6 +362,19 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- DrawerLayout侧滑菜单样例 -->
|
||||
<activity
|
||||
android:name=".sample.menu.DrawerLayoutActivity"
|
||||
android:label="@string/DrawerLayoutActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="com.zftlive.android.SAMPLE_CODE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- 静态注册短信广播接收器 -->
|
||||
<receiver android:name=".sample.sms.SMSBroadcastReceiver">
|
||||
<intent-filter android:priority="2147483647">
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 368 B |
Binary file not shown.
After Width: | Height: | Size: 324 B |
Binary file not shown.
After Width: | Height: | Size: 348 B |
Binary file not shown.
After Width: | Height: | Size: 196 B |
|
@ -0,0 +1,33 @@
|
|||
<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.support.v4.widget.DrawerLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<!-- The main content view -->
|
||||
<FrameLayout
|
||||
android:id="@+id/content_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<!-- The navigation drawer -->
|
||||
<ListView
|
||||
android:id="@+id/left_drawer"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="left"
|
||||
android:cacheColorHint="@android:color/transparent"
|
||||
android:choiceMode="singleChoice"
|
||||
android:divider="@color/lightgray"
|
||||
android:background="@color/white"
|
||||
android:dividerHeight="1.5dp"
|
||||
android:listSelector="@android:color/transparent"
|
||||
android:scrollbars="none" />
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
|
||||
</RelativeLayout>
|
|
@ -18,11 +18,12 @@
|
|||
<string name="AnimationInActivity">Activity切换过场动画示例</string>
|
||||
<string name="SMSOperationActivity">发送短信/拦截示例</string>
|
||||
<string name="BasicTestActivity">基本常用操作测试样例</string>
|
||||
<string name="DrawerLayoutActivity">DrawerLayout侧滑菜单</string>
|
||||
<!-- Android样例锦集label(结束) -->
|
||||
|
||||
|
||||
|
||||
<!-- 短信验证码/拦截示例(开始) -->
|
||||
<string name="sms_timer">获取验证码(%1$s)</string>
|
||||
<!-- 短信验证码/拦截示例(结束) -->
|
||||
|
||||
<!-- 自动获取表单示例(开始) -->
|
||||
<string name="tv_account">帐号:</string>
|
||||
|
@ -54,12 +55,19 @@
|
|||
<string name="btn_choice">选择</string>
|
||||
<!-- 短信操作示例(结束) -->
|
||||
|
||||
<!-- common意见反馈示例(开始) -->
|
||||
<string name="btn_submit">提交</string>
|
||||
<string name="hint_feedback">期待您的宝贵建议(1000字)</string>
|
||||
<!-- common意见反馈示例(结束) -->
|
||||
|
||||
|
||||
<!-- 基本操作示例(开始) -->
|
||||
<string name="btn_opengps">强制打开GPS</string>
|
||||
<string name="btn_call">直接拨打电话</string>
|
||||
<!-- 基本操作示例(结束) -->
|
||||
|
||||
<!-- DrawerLayout抽屉菜单示例(开始) -->
|
||||
<string name="drawer_close">关闭</string>
|
||||
<string name="drawer_open">打开</string>
|
||||
<!-- DrawerLayout抽屉菜单示例(结束) -->
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
package com.zftlive.android.sample.menu;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ActionBarDrawerToggle;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.zftlive.android.R;
|
||||
import com.zftlive.android.base.BaseActivity;
|
||||
|
||||
/**
|
||||
* 抽屉菜单
|
||||
*
|
||||
* @author 曾繁添
|
||||
* @version 1.0
|
||||
*
|
||||
*/
|
||||
public class DrawerLayoutActivity extends BaseActivity {
|
||||
private String[] mPlanetTitles;
|
||||
private DrawerLayout mDrawerLayout;
|
||||
private ActionBarDrawerToggle mDrawerToggle;
|
||||
private ListView mDrawerList;
|
||||
|
||||
@Override
|
||||
public int bindLayout() {
|
||||
return R.layout.activity_drawerlayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView(View view) {
|
||||
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
|
||||
// 绑定Listview
|
||||
mPlanetTitles = getResources().getStringArray(R.array.anim_type);
|
||||
mDrawerList = (ListView) findViewById(R.id.left_drawer);
|
||||
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
|
||||
android.R.layout.simple_list_item_1, mPlanetTitles));
|
||||
mDrawerList.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view,
|
||||
int position, long id) {
|
||||
setTitle(mPlanetTitles[position]);
|
||||
mDrawerList.setItemChecked(position, true);
|
||||
mDrawerLayout.closeDrawer(mDrawerList);
|
||||
}
|
||||
});
|
||||
|
||||
// 抽屉菜单
|
||||
mDrawerLayout.setDrawerShadow(R.drawable.view_fixheadtable_shadow_left,
|
||||
GravityCompat.START);
|
||||
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
|
||||
R.drawable.ic_menu_black_36dp, R.drawable.ic_menu_black_36dp,
|
||||
R.drawable.ic_expand_more_grey600_36dp) {
|
||||
public void onDrawerClosed(View view) {
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
};
|
||||
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doBusiness(Context mContext) {
|
||||
|
||||
// ActionBar配置 Note: getActionBar() Added in API level 11
|
||||
getActionBar().setDisplayShowHomeEnabled(true);
|
||||
getActionBar().setHomeButtonEnabled(true);
|
||||
getActionBar().setDisplayUseLogoEnabled(true);
|
||||
getActionBar().setLogo(R.drawable.ic_menu_black_36dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
mDrawerToggle.syncState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (mDrawerToggle.onOptionsItemSelected(item)) {
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
mDrawerToggle.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue