I am trying to implement a custom action bar. Here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/action_bar">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="test "/>
</FrameLayout>
And here is the Java code:
public class CustomActionBarActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayOptions(android.support.v7.app.ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
View customView = getLayoutInflater().inflate(R.layout.action_bar, null);
actionBar.setCustomView(customView);
Toolbar parent = (Toolbar) customView.getParent();
parent.setContentInsetsAbsolute(0, 0);
}
}
Result:

Here is the result with "developer options"> "show display frames"

source
share