第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有沒有一種簡單的方法可以將按鈕添加到子活動的操作欄?

有沒有一種簡單的方法可以將按鈕添加到子活動的操作欄?

紅顏莎娜 2023-03-09 10:43:36
我正在嘗試將按鈕添加到 android studio 應(yīng)用程序中的操作欄到子活動,但我只設(shè)法將它添加到主要活動。有人知道我該怎么做嗎?我希望“確定”按鈕位于我用橙色繪制的位置。帶有操作欄的主要活動。帶操作欄的兒童活動
查看完整描述

3 回答

?
藍(lán)山帝景

TA貢獻(xiàn)1843條經(jīng)驗 獲得超7個贊

您應(yīng)該為您的活動創(chuàng)建一個菜單:

里面res -> menu選擇new -> Menu資源文件

http://img1.sycdn.imooc.com//6409481b0001118b06540778.jpg

在您的新菜單 xml 文件中寫入以下內(nèi)容:


<?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/menu_action_ok"

        android:title="Ok"

        app:showAsAction="ifRoom" />

</menu>

基本上,您正在創(chuàng)建一個菜單,其中包含一個名為“確定”的選項,但如果需要,您可以有更多選項。如果需要,您還可以自定義此選項的視圖:


app:actionLayout="@layout/filter_ka"

在您的父活動中:


@Override

public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu.

    getMenuInflater().inflate(R.menu.menu_test, menu);

    return true;

}

R.菜單。menu_test是菜單文件的名稱。


最后要接收菜單選項的點擊,您應(yīng)該重寫以下函數(shù):


@Override

public boolean onOptionsItemSelected(MenuItem item) {

    // Handle action bar item clicks here. The action bar will

    // automatically handle clicks on the Home/Up button, so long

    // as you specify a parent activity in AndroidManifest.xml.

    int id = item.getItemId();



    if (id == R.id.menu_action_ok) {

        //Your code

        return true;

    }

    return super.onOptionsItemSelected(item);

}

現(xiàn)在你應(yīng)該有一個像這樣的菜單:

http://img1.sycdn.imooc.com//6409483100011be406240765.jpg

查看完整回答
反對 回復(fù) 2023-03-09
?
四季花海

TA貢獻(xiàn)1811條經(jīng)驗 獲得超5個贊

您必須為此創(chuàng)建一個菜單。假設(shè)你創(chuàng)建add_menu


<?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/action_add"

        android:title="ADD"

        app:showAsAction="ifRoom"/>


</menu>

創(chuàng)建菜單后,使用以下命令將其擴(kuò)展到您的子活動。


   @Override

    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.add_menu, menu);

        return true;

    }


查看完整回答
反對 回復(fù) 2023-03-09
?
幕布斯7119047

TA貢獻(xiàn)1794條經(jīng)驗 獲得超8個贊

您不必使用操作欄。您只能使用您想要的背景顏色的視圖。在您將按鈕設(shè)置在彩色區(qū)域上方之后。


在 Android Studio 中:


價值觀>風(fēng)格


用這個 :


<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

代替


 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

回到你的布局:


// Change your background with LinearLayout's background propoerty

   <LinearLayout

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

       android:orientation="horizontal"


       android:background="#FFA908"



       >



       // You can put here whatever you want. ?f you wish image or button.




       <Button

           android:layout_width="wrap_content"

           android:layout_height="wrap_content"

           android:text="Example"

           android:layout_gravity="center"

           android:layout_marginLeft="200dp"

           />


       <Button

           android:layout_width="wrap_content"

           android:layout_height="wrap_content"

           android:text="Example"

           android:layout_gravity="center"

           />




   </LinearLayout>

?f 你可以像這樣使用。您不需要使用操作欄。你可以輕松地創(chuàng)造任何你想要的東西。


查看完整回答
反對 回復(fù) 2023-03-09
  • 3 回答
  • 0 關(guān)注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號