我是新来的Android的开发,需要一些帮助:)我只是想添加自定义按钮的工具栏右侧。
我看到LinearLayouts和等几个解决方案...但我不知道是不是这样做正确的方式。
已经检查材料的设计和发现的顶栏,但不认为这是我需要的:P
谢谢!
创建自定义工具栏(toolbar.xml),你可以使用LinearLayout
容纳您的自定义设计:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="100dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
包括自定义工具栏到您的activity.xml:
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/toolbar" />
要访问Button
:
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Your logic
}
});