相关疑难解决方法(0)

我如何隐藏一个活动的菜单按钮

有一项没有菜单项的活动.所以我想隐藏菜单按钮.有没有办法实现这一目标?谢谢

android menu hide

9
推荐指数
2
解决办法
1万
查看次数

带有自定义布局的ActionBar在Android 4.4.2(KitKat)上不占用全屏宽度

我想显示一个带有自定义布局的Action Bar.自定义布局有三个ImageView,一个位于中心,另外两个位于操作栏的左右两端.必须没有后退按钮或操作项.

这是我用过的:

android.support.v7.app.ActionBar actionBar = getSupportActionBar();

actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);

ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
View actionBarView = LayoutInflater.from(this).inflate(resource, null); 
actionBar.setCustomView(actionBarView, lp);
Run Code Online (Sandbox Code Playgroud)

自定义布局正确充气,但不占据屏幕的整个宽度.这发生在Android 4.4.2(KitKat)上.在Gingerbread上,上述安排正常.

我在以下讨论中尝试了推荐的解决方案:

但问题仍然存在.必须有一种方法来强制布局占据整个屏幕宽度.

我正在使用V7 AppCompat库中的Action Bar.有没有人知道这个方法?

编辑1:

这是XML布局文件:

<RelativeLayout 
            xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="fill_horizontal"
            android:orientation="horizontal">

                    <ImageView
                         android:id="@+id/left_icon"
                         android:background="@drawable/leftbutton"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_marginLeft="10dp"
                         android:layout_alignParentLeft="true"
                         android:layout_centerVertical="true"
                         android:adjustViewBounds="true"
                         android:scaleType="centerInside"
                         android:clickable="true"
                         android:onClick="leftButtonPressed"
                         android:hapticFeedbackEnabled="true"
                    />

                    <ImageView
                         android:id="@+id/center_icon"
                         android:background="@drawable/centertitle"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_centerInParent="true"
                         android:adjustViewBounds="true"
                         android:scaleType="centerInside"
                    />

                    <ImageView
                         android:id="@+id/right_icon"
                         android:background="@drawable/rightbutton"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_marginRight="10dp"
                         android:layout_alignParentRight="true"
                         android:layout_centerVertical="true"
                         android:adjustViewBounds="true"
                         android:scaleType="centerInside"
                         android:clickable="true" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-actionbar

5
推荐指数
1
解决办法
7215
查看次数

检测菜单按钮事件

我想禁用菜单按钮.我读了很多文章,没有任何作品.
我甚至无法检测菜单按钮按下的事件.覆盖onKeyDown(),onKeyUp(),onPrepareOptionsMenu(),onCreateOptionsMenu()等方法无法正常工作.我真的很绝望,请帮忙.

public class MainActivity extends Activity{
TranslateAnimation animateTopLayer;
Button btnOk;
ImageView ivLockMechanism;
ViewGroup rlTopLayer;
FramesSequenceAnimation anim;

@Override
public void onAttachedToWindow() {
    getWindow().addFlags(WindowManager.LayoutParams. FLAG_DISMISS_KEYGUARD);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent lockServiceIntent = new Intent(getApplicationContext(),LockService.class);
    startService(lockServiceIntent);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.test);
    rlTopLayer = (ViewGroup) findViewById(R.id.rlTopLayer);
    ivLockMechanism = (ImageView) findViewById(R.id.ivLockMechanism);
    btnOk = (Button) findViewById(R.id.btnOk);
    btnOk.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            rlTopLayer.startAnimation(animateTopLayer);
        }
    });
    Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.pg_0);
    ivLockMechanism.setImageBitmap(b);
    anim = AnimationsContainer.getInstance().unlockMechanismAnimation(ivLockMechanism);
    animateTopLayer = new TranslateAnimation(0, …
Run Code Online (Sandbox Code Playgroud)

android

1
推荐指数
1
解决办法
3335
查看次数

标签 统计

android ×3

android-actionbar ×1

android-layout ×1

hide ×1

menu ×1