मैं इस लक्ष्य को हासिल करने के लिए कोशिश कर रहा हूँ के अधिकार के लिए कस्टम दृश्य जोड़ें:(लाल रंग की पृष्ठभूमि के साथ <code>toolbar</code> में एक टाइमर) उपकरण पट्टी
मैं toolbar
में customView
जोड़ने की कोशिश कर रहा हूँ। यह हमेशा पीछे तीर के बगल में चरम बाएं होने पर समाप्त होता है। नीचे दी गई छवि में YP
टेक्स्ट की तरह एक कस्टम Textview
टूलबार में जोड़ा गया है। ।
toolbar
के लिए कोड:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
android:id="@+id/base_activity_toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
लेआउट जोड़ने के लिए कोड:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:gravity="end"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:text="yp"
android:layout_height="wrap_content"/>
</LinearLayout>
मैं:
LayoutInflater mInflater= LayoutInflater.from(context);
View mCustomView = mInflater.inflate(R.layout.textview, null);
toolbar.addView(mCustomView);
यह लेआउट मैं परीक्षण के लिए अभी द्वारा जोड़ा जा रहा है कुछ हद तक याद आ रही है, पता नहीं लगा सका। मेरे बाल खींच कर बाहर।
बदलें LinearLayout के '' match_parent' को layout_width' काम किया। –