Material Design——界面设计
1.Toolbar,标题栏
1】修改配置文件
<application android:name="org.litepal.LitePalApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.Android"> <activity android:name=".MainActivity" android:label="Dummer"> ...... </activity> </application>
2】添加xml文件,目录res-meau-toolbar.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/backup" android:icon="@drawable/ic_small" android:title="Backup" app:showAsAction="always" /> <item android:id="@+id/deletes" android:icon="@drawable/ic_biggest" android:title="Delete" app:showAsAction="ifRoom" /> <item android:id="@+id/setting" android:icon="@drawable/ic_car24" android:title="Settings" app:showAsAction="never" /> </menu>
3】修改activity,增加两个重写方法
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.toolbar, menu); return true; } @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.backup: Log.i(TAG, "you clicked Backup"); break; case R.id.deletes: Log.i(TAG, "you clicked Delete"); break; case R.id.setting: Log.i(TAG, "you clicked Settings"); break; default: break; } return true; }
效果如下,Pass
2】