我正在开发一款Android应用程序,需要在操作栏中添加一个按钮。 这是我的活动和Java文件。 因此,我需要在工具栏右侧放置一个按钮。 提前致谢。
content_b2_bdeliveries.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.ideabiz.riderapplication.ui.B2BDeliveriesActivity"
tools:showIn="@layout/activity_b2_bdeliveries">
//remaining code;
</LinearLayout>
activity_b2_bdeliveries.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.ideabiz.riderapplication.ui.B2BDeliveriesActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_b2_bdeliveries" />
</android.support.design.widget.CoordinatorLayout>
B2BDeliveriesActivity.java:
public class B2BDeliveriesActivity extends AppCompatActivity {
private final String TAG_NAME="B2BActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b2_bdeliveries);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
ActionBar actionBar = getSupportActionBar();
//Log.d(TAG_NAME,actionBar.toString());
if (actionBar != null) {
try {
actionBar.setDisplayHomeAsUpEnabled(true);
} catch (Exception e) {
Crashlytics.logException(e);
Log.d(TAG_NAME, "Null Pointer from setDisplayHomeAsUpEnabled" + e.getMessage());
Utilities.issueTokenUpload("Null Pointer from setDisplayHomeAsUpEnabled" + e, sharedPreferences.getInt("tripId", 999999), sharedPreferences.getString("driverPhoneNo", "9999999999"), sharedPreferences.getString("driverName", "default"), getResources().getString(R.string.version));
}
}
}
return true; }
- Manikanta Siripella