gpt4 book ai didi

android - 抽屉导航 : text is hidden below actionbar?

转载 作者:搜寻专家 更新时间:2023-11-01 08:51:20 27 4
gpt4 key购买 nike

我将抽屉导航添加到我的应用程序中。一切正常,但现在我正在尝试向菜单添加一个简单的 textView,但没有成功。问题在于文本隐藏在 actionBar 本身之下。即使距顶部 50dp 边距也不够。

关于如何解决这个问题,您有什么建议吗?

我的主要 Activity :

<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 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container"
android:fitsSystemWindows="true"
android:clipToPadding="false"/>
<!-- The navigation drawer -->
<FrameLayout
android:id="@+id/left_drawer"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="@color/dark_brown">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:textSize="40dp"
android:textColor="#ffffff"
android:id="@+id/textView"
android:layout_marginTop="50dp"
android:layout_marginLeft="20dp"
android:gravity="center_vertical"/>
</FrameLayout>
</android.support.v4.widget.DrawerLayout>

我的主要 Activity 类:

public class MainActivity extends ActionBarActivity {

private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private DatabaseHandler database;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Handle application side menu
sideMenu();

// Set tint for android bar (only for KitKat version)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(R.color.action_bar_bg);
}

// Create system objects
database = new DatabaseHandler(this);
final Statistics statistic = new Statistics(database);

// Create main fragment and point app to it
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new MainFragment(database, statistic))
.commit();
}
}

private void sideMenu() {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
this, // host Activity
mDrawerLayout, // DrawerLayout object
R.drawable.ic_drawer, // nav drawer icon to replace 'Up' caret
R.string.drawer_open, // "open drawer" description
R.string.drawer_close // "close drawer" description
) {
// Called when a drawer has settled in a completely closed state.
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getSupportActionBar().setTitle(R.string.drawer_close);
}

// Called when a drawer has settled in a completely open state.
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getSupportActionBar().setTitle(R.string.drawer_open);
}
};

// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns
// true, then it has handled the app icon touch event
return mDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
}

@Override
protected void onDestroy() {
super.onDestroy();
database.closeDatabase();
}
}

最佳答案

您想将 fitsSystemWindows 和 clipToPadding 分配给 Navigation Drawer fragment (很可能是 ListView)

像这样的——

<ListView 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:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#cccc"

android:fitsSystemWindows="true"
android:clipToPadding="false"

/>

但在您的情况下,您在 activity_main 本身上使用 FrameLayout 来填充抽屉内容。所以你必须将这两个属性应用到 FrameLayout

<FrameLayout
android:id="@+id/left_drawer"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"

android:fitsSystemWindows="true"
android:clipToPadding="false"

android:background="@color/dark_brown">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:textSize="40dp"
android:textColor="#ffffff"
android:id="@+id/textView"
android:gravity="center_vertical"/>
</FrameLayout>

另外,请注意,您不再需要关注您的 TextView。

android:layout_marginTop="50dp"
android:layout_marginLeft="20dp"

关于android - 抽屉导航 : text is hidden below actionbar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23117644/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com