我正在使用ActionsContentView库作为侧面菜单栏.
https://play.google.com/store/apps/details?id=sample.actionscontentview
最初我尝试在支持库中使用Google的NavigationDrawer对象.但是我放弃了它,因为我需要一个非listview类型的布局用于视图的某些部分.
无论如何,我想知道这个推理是否有缺陷.我的菜单的一部分是使用非列表视图和一些相当复杂的自定义布局,可以在滚动视图中动态添加,或者最终可能最终成为列表视图中的自定义适配器.
无论如何,我需要ActionsContentView库已经提供的灵活性
我可以在NavigationDrawer中使用非列表视图吗?
这是我的NavigationDrawer列表项的定义方式.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="15dp">
<ImageView
android:id="@+id/drawer_list_item_icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical|left"
android:orientation="vertical" >
<TextView
android:id="@+id/drawer_list_item_title"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:textColor="#00FFFF"
android:singleLine="true" />
<TextView
android:id="@+id/drawer_list_item_subtitle"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我正在使用ActionBarSherlock库和SherlockNavigationDrawer.
一切都在我的Android 4.3设备中完美运行.
但在我的2.3.3设备中,我遇到了一个奇怪的问题.
这是初始NavigationDrawer的外观.

问题场景:我按住任何listItem,然后向上或向下拖动我的手指(同时仍然按住)向另一个listItem.
就是这种情况发生的时候.

所有listItem都以白色突出显示,直到并且除非以正常方式单击另一个listItem(即使我关闭并重新打开NavDrawer,仍然整个列表仍然以白色突出显示).
但这不会发生在Android 4.3中.
它只发生在Android 2.3.3中(可能发生在所有前ICS设备上).
这是兼容性库的问题吗?
这是我在values-v11文件夹中唯一的附加代码,因为Android 2.3中没有"activatedBackgroundIndicator".
<resources>
<style name="listViewActivatedStyle">
<item name="android:background">?android:attr/activatedBackgroundIndicator</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
Android 2.3无法访问上述代码.这是它给出这个问题的原因吗?或者兼容性库中存在错误?
任何建议都将深表感谢.
现在我正在寻找一个解决方案,在右侧滑动关闭时隐藏键盘,因为在这张幻灯片中我有一个EditText,当我关闭菜单时,键盘仍然打开.
最后,当我打开菜单时,布局会覆盖主要内容.所以我想知道是否有一种简单的方法可以使主要内容跟随菜单的运动,Facebook就像?
我正在尝试实现两个选项卡,还有一个导航抽屉.我可以单独做两个,但当我尝试将两者结合起来时,我会遇到问题.我最初有用于创建我的两个标签的代码和我的MainActivity中的导航抽屉,当时这是一个片段活动,但是当我清楚地知道导航抽屉上有一个Home选项时,我决定重构代码标签插入一个带有标签的片段,然后像以前一样用两个片段填充.
在启动时看起来很好但是当我点击导航抽屉中的home选项时,每个选项卡中的片段似乎被剥离,每次单击选项时都会添加两个选项卡.
private void selectItem(int position) {
Fragment fragment = new NullFragment();
switch (position){
case 0:
fragment = new HomeFragment();
break;
case 1:
//Placeholder
fragment = new PlanetFragment();
}
// update the main content by replacing fragments
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
// update selected item and title, then close the drawer
drawerListView.setItemChecked(position, true);
setTitle(drawerItemTitles[position]);
drawerLayout.closeDrawer(drawerListView);
} else {
// error in creating fragment
Log.e("MainActivity", "Error in creating fragment");
}
}
Run Code Online (Sandbox Code Playgroud)
HomeFragment.java
public class …Run Code Online (Sandbox Code Playgroud) tabs android android-fragments navigation-drawer android-nested-fragment
我有这个类延伸BaseAdapter,我使用插入一个icon和一个textView用于的每一行listView是一个抽屉内
public class NavRightDrawerListAdapter extends BaseAdapter {
private Context context;
LinkedList<String> userNameUsedForListView;
Map<String, Bitmap> urlUserImage;
public NavRightDrawerListAdapter(Context context, LinkedList<String> userNameUsedForListView, Map<String, Bitmap> returnBitMapFromURL) {
this.context = context;
this.userNameUsedForListView = userNameUsedForListView;
this.urlUserImage = returnBitMapFromURL;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int count = 0;
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.drawer_list_of_action, null);
}
ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
TextView txtTitle = (TextView) …Run Code Online (Sandbox Code Playgroud) 案例如下:我有两种类型的用户,type1和type2.两者都必须登录才能进入具有导航抽屉的主要活动.导航抽屉中的项目取决于用户的类型.在知道用户类型后,如何在运行时更改导航抽屉的项目.
MainActivity.java
package com.example.motassem.navdrawer;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.preference.PreferenceManager;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private static final String SELECTED_ITEM_ID = "selected_item_id";
private static final String FIRST_TIME = "first_time";
private Toolbar mToolbar;
private NavigationView mDrawer;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private int mSelectedID;
private boolean mUserSawDrawer = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//mMainLayout = …Run Code Online (Sandbox Code Playgroud) 我正在使用android studio navigationview。
但是我将Navigationview的颜色背景更改为黑色,
并且子标题的分隔线消失了(因为分隔线也是黑色的)。
子标题标题也消失了。
有没有办法将这些属性更改为白色或任何颜色?
这是菜单的XML。
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:id="@+id/nav_header"
android:checkableBehavior="single">
<item
android:id="@+id/nav_home"
android:checked="true"
android:icon="@drawable/ic_home_black_24dp"
android:title="Home" />
<item
android:id="@+id/nav_search"
android:icon="@drawable/ic_search_black"
android:title="Search Location" />
<item
android:id="@+id/nav_fav"
android:icon="@drawable/ic_favorite"
android:title="Favorites" />
<item
android:id="@+id/nav_recent"
android:icon="@drawable/ic_nav_route"
android:title="Recent Location" />
<item
android:id="@+id/nav_route"
android:icon="@drawable/ic_place"
android:title="Route" />
</group>
<item
android:id="@+id/navigation_subheader"
android:title="Others">
<menu>
<item
android:id="@+id/nav_settings"
android:checkable="true"
android:icon="@drawable/ic_settings"
android:title="Settings" />
<item
android:checkable="true"
android:id="@+id/nav_about"
android:icon="@android:drawable/ic_menu_send"
android:title="About" />
</menu>
</item>
</menu>
Run Code Online (Sandbox Code Playgroud)
谢谢!
我想在NavigationView的菜单项中设置android:ellipsize ="end".在我目前的实现中,当菜单项中的文本太长时,它只是在最后切割.这是我到目前为止所尝试的:
<android.support.design.widget.NavigationView
app:itemTextAppearance="@style/AppTheme.Widget.NavigationView.TextAppearance"
android:id="@+id/navigation"
style="@style/AppTheme.Widget.NavigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/drawer_view"/>
<style name="AppTheme.Widget.NavigationView" parent="Widget.Design.NavigationView">
<item name="android:textAppearance">@style/AppTheme.Widget.NavigationView.TextAppearance</item>
<item name="android:background">@color/drawer_background</item>
<item name="itemTextColor">@color/color_drawer_item</item>
<item name="itemIconTint">@color/color_drawer_item</item>
</style>
<style name="AppTheme.Widget.NavigationView.TextAppearance">
<item name="android:ellipsize">end</item>
<item name="android:maxLines">1</item>
</style>
Run Code Online (Sandbox Code Playgroud)
编辑:
此处描述了另一种可能的解决方案:Android NavigationView:不显示完整项目而不是截断
我想从工具栏中删除3个点,并且还想在该位置添加带有textview的图像.每个片段活动的图像和文本视图都不同.
任何人都可以告诉我如何使工具栏透明.
我是初学者.我想知道,如何添加一个项目,Navigation Drawer其中的图标将添加到项目标题的右侧.
我想要像这张照片一样.

但是怎么样?我想要像这个Youtube项目一样添加项目.
这是Navigation Drawer菜单:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Social Links">
<menu>
<item
android:id="@+id/nav_facebook"
android:icon="@drawable/ic_menu_facebook"
android:title="Facebook"
/>
<item
android:id="@+id/nav_youtube"
android:icon="@drawable/ic_menu_youtube"
android:title="Youtube"
/>
<item
android:id="@+id/nav_twitter"
android:icon="@drawable/ic_menu_twitter"
android:title="Twitter"
/>
</menu>
</item>
</menu>
Run Code Online (Sandbox Code Playgroud)
我还将此代码附加到Manifest:
android:supportsRtl="true"
Run Code Online (Sandbox Code Playgroud) android ×10
menuitem ×2
baseadapter ×1
drawerlayout ×1
java ×1
keyboard ×1
listview ×1
tabs ×1