J'ai implémenté une barre d'actions personnalisée qui contient une image et un bouton. Cela fonctionne très bien mais cette barre d'action personnalisée s'affiche sous la barre d'action principale. Comment devrais-je la remplacer dans la barre principale? Veuillez ne pas confondre avec le nom ou le titre de l'application. La barre d'actions personnalisée ne remplace pas la barre d'actions par défaut
Code pour MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
View v1 = getLayoutInflater().inflate(R.layout.custom_drawer_item, null);
actionBar.setCustomView(v1);
}
}
Code pour customlayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#00897B" >
<Button
android:layout_width="190dp"
android:layout_height="wrap_content"
android:text="Register an event"
android:textColor="#ffffff"
android:background="#4db6ac"
android:id="@+id/button1"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:id="@+id/imageView1"
android:src="@drawable/refr"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="32dp" />
</RelativeLayout>