使菜单按钮不可见

时间:2018-10-09 14:24:33

标签: android button menu

我知道有人问过很多,但是我的应用程序有问题。看到我在菜单文件夹的menu.xml文件中添加了按钮,它显示了,但是横幅广告将其覆盖在应用程序的底部,而在顶部,按钮根本没有显示 这是我的应用的图片:Ad covers menu view pic 1也是这个 without ads pic 2。再加上我想放大分享和评分按钮的大小... 这就是我希望菜单按钮像这样的方式:menu button pic 1 menu pic 2

这是我的菜单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">

    <item
        android:id="@+id/privacy"
        android:title="@string/privacy_policy"
        android:layout_width="150sp"
        android:textSize="150sp"
        android:layout_height="150sp" />

    <item
        android:id="@+id/Disclaimer"
        android:title="@string/disclaimer"
        android:layout_width="150sp"
        android:textSize="150sp"
        android:layout_height="150sp" />

    <item
        android:id="@+id/More"
        android:title="@string/more_apps"
        android:layout_width="150sp"
        android:textSize="150sp"
        android:layout_height="150sp" />
</menu>

这是我的Java活动代码:

import com.xxx.xxx.database.DataBaseHelper;
import com.xxx.xxx.R;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;

public class MainActivity extends Activity {

    InterstitialAd  mInterstitialAd;
    AdRequest adRequest;
    Button start;
    ProgressBar progressBar ;
    private final int SPLASH_DISPLAY_LENGTH = 2000;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main_activity);

        start = (Button) findViewById(R.id.start);
        DataBaseHelper.setmDatabase(this);
        AppRater.setAPP_PNAME(this);



        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId(SettingsApp.Interstitial);
        progressBar=(ProgressBar) findViewById(R.id.progressBar1);
        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                requestNewInterstitial();
            }
        });

        requestNewInterstitial();

        new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
                /* Create an Intent that will start the Menu-Activity. */
               progressBar.setVisibility(View.GONE);
               start.setVisibility(View.VISIBLE);
            }
        }, SPLASH_DISPLAY_LENGTH);

        start.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent=new Intent(MainActivity.this,ListViewsItems.class);
                //intent.putExtra("id",""+itemClicked.getDirection());
                //startActivityForResult(intent, 1);
                startActivity(intent);
                if (mInterstitialAd.isLoaded())  mInterstitialAd.show();
                finish();
                //else Toast.makeText(Start.this, "nonLoaded", Toast.LENGTH_SHORT);
            }
        });
    }

    public boolean onCreateOptionsMenu(Menu menu) {

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
            case R.id.privacy:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://xxx.xxx")));
                return true;
            case R.id.Disclaimer:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://xxx.xxx")));
                return true;
            case R.id.More:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=" + "xxx")));// ADD YOUR DEVELOPER NAME HERE USE + FOR SPACE
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }

    }

    private void requestNewInterstitial() {
         AdRequest adRequest = new AdRequest.Builder().build();
         mInterstitialAd.loadAd(adRequest);
    }


}

1 个答案:

答案 0 :(得分:0)

您缺少活动中的工具栏。

尝试将其添加到您活动的xml中:

<android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            ... />

然后将其设置为工具栏:

setSupportActionBar(findViewById(R.id.toolbar))