每日总结2023/2/25

今天继续进行安卓学习

 

 

 

 

 

 

 

 

 

 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <Toolbar
        android:id="@+id/tb"
        android:background="@color/colorAccent"
        android:navigationIcon="@drawable/ic_launcher_background"
        android:title="标题"
        android:layout_width="wrap_content"
        android:layout_height="?attr/actionBarSize"
        android:titleTextColor="@color/colorPrimary"
        android:titleMarginStart="50dp"
        android:subtitle="子标题"
        android:subtitleTextColor="@color/colordu"
        android:logo="@mipmap/ic_launcher"
        />
    <Toolbar
        android:id="@+id/tb2"
      android:layout_marginTop="10dp"
        android:background="@color/colorAccent"
        android:navigationIcon="@drawable/ic_launcher_background"
        android:title="标题"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:titleTextColor="@color/colorPrimary"
        android:titleMarginStart="50dp"
        android:subtitle="子标题"
        android:subtitleTextColor="@color/colordu"
        android:logo="@mipmap/ic_launcher"
        tools:ignore="NewApi"/>
    <Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_marginTop="10dp"

        android:background="@color/colorPrimary"
        android:navigationIcon="@drawable/ic_launcher_background"


        tools:ignore="NewApi">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="标题" />
    </Toolbar>




    
    
    
</LinearLayout>

  

package com.example.a86191.mytoolbar;

import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toolbar;

public class MainActivity extends AppCompatActivity {
  public static final String TAG="MainActivity";
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar=findViewById(R.id.tb);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.e(TAG, "onClick: toolbar被点击了");
            }
        });
        Toolbar toolbar2=findViewById(R.id.tb2);
        toolbar2.setNavigationIcon(R.drawable.ic_launcher_foreground);
        toolbar2.setTitle("标题");
        toolbar2.setNavigationOnClickListener(new View.OnClickListener(){


            @Override
            public void onClick(View view) {
                Log.e(TAG, "onClick: toolbar2被点击了");
            }
        });
    }
}

  

posted @ 2023-02-25 13:43  橘子味芬达水  阅读(4)  评论(0编辑  收藏  举报