久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Android基于Toolbar實(shí)現(xiàn)頂部標(biāo)題欄及后退鍵

瀏覽:7日期:2022-09-22 14:04:41

最近設(shè)計(jì)安卓里面有個(gè)標(biāo)題欄,里面有個(gè)后退鍵,可以完成后退之類的功能。

好,剛好可以用Toolbar去實(shí)現(xiàn)

Android基于Toolbar實(shí)現(xiàn)頂部標(biāo)題欄及后退鍵

上代碼:activity_main.xml

<?xml version='1.0' encoding='utf-8'?><android.support.design.widget.CoordinatorLayout 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' android:layout_width='match_parent' android:layout_height='match_parent' tools:context='.MainActivity'> <android.support.design.widget.AppBarLayout android:layout_width='match_parent' android:layout_height='wrap_content' android:theme='@style/AppTheme.AppBarOverlay'> <android.support.v7.widget.Toolbar android: android:layout_width='match_parent' android:layout_height='wrap_content' android:background='?attr/colorPrimary' app:popupTheme='@style/AppTheme.PopupOverlay'> <TextViewandroid:layout_width='wrap_content'android:layout_height='wrap_content'android:layout_centerInParent='true'android:layout_gravity='center'android:text='設(shè)置'android:textSize='22sp' /> </android.support.v7.widget.Toolbar> </android.support.design.widget.AppBarLayout></android.support.design.widget.CoordinatorLayout>

這里需要引用styles.xml在里面加樣式

<resources> <!-- Base application theme. --> <style name='AppTheme' parent='Base.Theme.AppCompat.Light'> <!-- Customize your theme here. --> <item name='colorPrimary'>@color/colorPrimary</item> <item name='colorPrimaryDark'>@color/colorPrimaryDark</item> <item name='colorAccent'>@color/colorAccent</item> </style> <style name='AppTheme.NoActionBar'> <item name='windowActionBar'>false</item> <item name='windowNoTitle'>true</item> </style> <style name='AppTheme.AppBarOverlay' parent='ThemeOverlay.AppCompat.Dark.ActionBar' /> <style name='AppTheme.PopupOverlay' parent='ThemeOverlay.AppCompat.Light' /></resources>

最后主程序:

package action.sun.com.testtoobar1;import android.os.Bundle;import android.support.design.widget.FloatingActionButton;import android.support.design.widget.Snackbar;import android.support.v7.app.AppCompatActivity;import android.support.v7.widget.Toolbar;import android.view.View;import android.view.Menu;import android.view.MenuItem;import android.view.Window;import android.view.WindowManager;import android.widget.Toast;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /*getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); //設(shè)置全屏*/ setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); //一定要加,為了去掉本身的標(biāo)題文字 toolbar.setTitle(''); //初始化toolbar setSupportActionBar(toolbar); //左邊的小箭頭(注意需要在setSupportActionBar(toolbar)之后才有效果) toolbar.setNavigationIcon(R.mipmap.back); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. Toast.makeText(MainActivity.this, '選擇了菜單', Toast.LENGTH_SHORT).show(); //初始化右邊的菜單選項(xiàng) //getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @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(); Toast.makeText(MainActivity.this, '選擇了后退按鈕='+id, Toast.LENGTH_SHORT).show(); //noinspection SimplifiableIfStatement return super.onOptionsItemSelected(item); }}

到此代碼完畢,就能夠完成需要上圖實(shí)現(xiàn)的效果了

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 久久人人爽人人爽 | 亚洲精品国产一区 | 欧美日韩中文 | yy6080久久伦理一区二区 | 国产一级片一区二区三区 | 国产精品无码永久免费888 | 国产精品视频不卡 | 欧美xxxx网站 | 91久久久久久久久 | 亚洲综合欧美 | 激情亚洲| 一区二区三区日韩 | 免费一级黄色电影 | www.国产91 | 国产三级一区二区 | 日韩精品99| 日韩成人国产 | 国产亚洲精品久久久久动 | 成人欧美一区二区三区黑人孕妇 | 久久一区二区三区四区 | 成人免费毛片高清视频 | 日韩一二三区视频 | 日韩欧美国产精品综合嫩v 高清av网站 | 国产精品久久久久久久久免费 | 精品视频 免费 | 日韩一区中文字幕 | 久久综合中文字幕 | 成人免费一区二区三区视频网站 | 国产一级毛片在线视频 | 精品影院 | 伊人欧美视频 | 日韩在线精品 | 成人av片在线观看 | 欧美亚洲另类在线 | 91 在线| 杏导航aⅴ福利网站 | 欧美自拍视频一区 | 精品午夜久久久 | www.久久| 久久99这里只有精品 | 欧美日韩三区 |