v7小部件工具栏未显示,为什么? [英] v7 widget toolbar not showing, why?

查看:90
本文介绍了v7小部件工具栏未显示,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我好近.我已经使用libs正确设置了android studio项目,该项目进行了编译,并且模拟器和设备运行了该应用程序.我试图摆脱较旧设备的底部按钮弹出菜单,并替换为v7 appcompat工具栏.旧的操作栏消失了,但是菜单膨胀仍然膨胀到旧的弹出菜单. 我从启动屏幕开始,然后应用程序主界面显示数据库视图活动.这意味着我必须动态加载工具栏. 我现在想的唯一剩下的就是样式/主题或setcontent(this)的顺序,以显示主应用程序/数据库视图屏幕. 另外,我没有适用于HTC evo设备的正确模拟器,因此设备按钮不显示.我相信这就是为什么很多开发人员都不会显示工具栏的原因.当我在真实设备上安装apk时,我可以使用菜单按钮.这就是我能够看到菜单不在工具栏中的方式.该仿真器不显示任何按钮,也不显示任何工具栏,因此使用较新设备的仿真器上的开发人员将永远不会看到此信息. 我希望这足以让任何人抓住我的陷阱. 提前致谢. 以下是代码段:

I am so close. I have the android studio project set up correctly with libs, the project compiles, and the emulators and device run the app. I am trying to get rid of the bottom button popup menu of older devices and replace with v7 appcompat toolbar. The old action bar is gone but the menu inflate still inflates to the old popup menu. I start off using a splashscreen then the app main shows the database view activity. This means I have to dynamically load the toolbar. My thinking now is the only place I have left to work out is the styles/themes or the order of setcontent(this) to display the main app/database view screen. Also I dont have the correct emulator for the HTC evo device so the device buttons dont show. I believe this is why alot of developers post that the toolbar doesnt show. When I install apk on real device i can the use the menu button. This is how I am able to see that the menu is not in the toolbar. The emulator shows no buttons plus no toolbar so a developer on an emulator of newer devices would never see this. I hope this enough to go on for any one to catch my pitfall here. Thanks in advance. Here are codes snippets:

styles.xml:

styles.xml:

<resources>
<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<!--<style name="AppTheme" parent="AppBaseTheme">-->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">true</item>
    <item name="android:textColor">#000000</item>
</style>
</resources>

Toolbarmenu.xml:

Toolbarmenu.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
    <item
        android:id="@+id/add"
        android:icon="@android:drawable/ic_menu_add"
        app:showAsAction="ifRoom"
        android:title="@string/app_name"/>
    <item
        android:id="@+id/reset"
        android:icon="@android:drawable/ic_menu_revert"
        app:showAsAction="ifRoom"
        android:title="@string/action_settings"/>
    <item
        android:id="@+id/about"
        android:icon="@android:drawable/ic_dialog_info"
        app:showAsAction="ifRoom"
        android:title="@string/hello_world">
    </item>
    <item
        android:id="@+id/exit"
        app:showAsAction="ifRoom"
        android:title="@string/Menu">
    </item>
</menu>

Manifest.xlm:

Manifest.xlm:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.loadrunner"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="com.loadrunner.SplashScreenActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Translucent.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.loadrunner.MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar">
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>

lrtoolbar.xml

lrtoolbar.xml

        <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:background="#2196f3"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:elevation="4dp"
        android:minHeight="200dp">
    </android.support.v7.widget.Toolbar>

</LinearLayout>

Layout_main.xml:

Layout_main.xml:

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".SplashScreenActivity"
    android:visibility="visible"
    android:background="@color/black">


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageViewSplashLogo"
        android:src="@drawable/shoppingcartloading"
        android:visibility="visible"
        android:contentDescription="@string/app_name"
        android:scaleType="fitCenter"
        android:cropToPadding="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:background="@color/black" />
  </RelativeLayout>

最后是代码:

import android.app.ActionBar;
import android.app.Activity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.SpinnerAdapter;
import android.widget.Toast;

import com.Table.TableMainLayout;


public class MainActivity extends AppCompatActivity {

    final String TAG = "MainActivity.java";
    public static DatabaseHandler db;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //Log.d("SplashMainActivityonCre", "made it");
        db = new DatabaseHandler(this);
        db.getWritableDatabase();
        db.insertFast(100);
        int dbreccnt = db.countRecords();
        //Log.d("SplashAfterDBCreate", "made it");
        //Log.d("AppLoadrunner ", "Loadrunner record count " + dbreccnt);

        Toolbar LrToolBar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(LrToolBar);
        //getSupportActionBar().setDisplayShowHomeEnabled(true);
        //LrToolBar.setNavigationContentDescription(getResources().getString(R.string.app_name));
        setContentView(new TableMainLayout(this));

TableMainLayout开始:

TableMainLayout start:

package com.Table;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
//import android.database.Cursor;

import com.loadrunner.DatabaseHandler;
import com.loadrunner.R;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;


public class TableMainLayout extends RelativeLayout {

    public final String TAG = "TableMainLayout.java";

推荐答案

我也许得到了答案:您只是在setContentView()方法之前获得了工具栏... 只需尝试:

I have maybe the answer : you just get your toolbar before setContentView() method... Just try this :

    setContentView(new TableMainLayout(this));
    Toolbar LrToolBar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(LrToolBar);
    //getSupportActionBar().setDisplayShowHomeEnabled(true);
    //LrToolBar.setNavigationContentDescription(getResources().getString(R.string.app_name));

希望它将对您有帮助

这篇关于v7小部件工具栏未显示,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆