私自身のアイコンをActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle)に追加しようとしています。カスタムアイコンは表示されていますが、クリックに反応していません。左から右に指をスライドさせるとサイドメニューが表示されますが、クリックは機能しません。 私はこのソリューションを試しましたが、機能しており、ツールバーを使用したくありません。ツールバーなしでこのアイコンを追加するソリューションをご希望の場合、like this。ActionBarDrawerToggleは表示されていますが、onClickが機能していません
これは私のコードです。大変申し訳ございません。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.layout_for_title);
CustomTextViewToolbar head=(CustomTextViewToolbar)findViewById(getResources().getIdentifier("mytext", "id", getPackageName()));
head.setText("Home");
ImageView gender = (ImageView)findViewById(getResources().getIdentifier("gender" , "id" , getPackageName()));
gender.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialog_gender);
dialog.show();
CircularImageView male = (CircularImageView)dialog.findViewById(R.id.male) ;
male.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
CircularImageView female = (CircularImageView)dialog.findViewById(R.id.female) ;
female.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
CircularImageView kids = (CircularImageView)dialog.findViewById(R.id.kids) ;
kids.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
});
ImageView imageView = (ImageView)findViewById(getResources().getIdentifier("show_cart" , "id" , getPackageName()));
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getBaseContext() , CustomerCartActivity.class));
}
});
setContentView(R.layout.customer_home_screen);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mActivityTitle = getTitle().toString();
mExpandableListView = (ExpandableListView) findViewById(R.id.navList);
initItems();
LayoutInflater inflater = getLayoutInflater();
View listHeaderView = inflater.inflate(R.layout.nav_header, null, false);
mExpandableListView.addHeaderView(listHeaderView);
mExpandableListData = ExpandableListDataSource.getData(this);
mExpandableListTitle = new ArrayList(mExpandableListData.keySet());
addDrawerItems();
setupDrawer();
if (savedInstanceState == null) {
selectFirstItemAsDefault();
}
mDrawerToggle.setDrawerIndicatorEnabled(false);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mDrawerToggle.setHomeAsUpIndicator(R.drawable.menu_icon);
coverFlow = (FeatureCoverFlow) findViewById(R.id.coverflow);
mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
drawer.openDrawer(GravityCompat.START);
}
}
});
mDrawerLayout.setDrawerListener(mDrawerToggle);
horizontal_recycler_view= (RecyclerView) findViewById(R.id.horizontal_recycler_view);
data = fill_with_data();
horizontalAdapter=new HorizontalAdapter(data, getApplication());
LinearLayoutManager horizontalLayoutManager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false);
horizontal_recycler_view.setLayoutManager(horizontalLayoutManager);
horizontal_recycler_view.setAdapter(horizontalAdapter);
coverFlowOne = (FeatureCoverFlow) findViewById(R.id.coverflow_one);
coverFlowTwo = (FeatureCoverFlow) findViewById(R.id.coverflowtwo);
settingDummyData();
adapter = new CoverFlowAdapter(this, games);
coverFlow.setAdapter(adapter);
coverFlow.setOnScrollPositionListener(onScrollListener());
coverFlowOne.setAdapter(adapter);
coverFlowOne.setOnScrollPositionListener(onScrollListener());
coverFlowTwo.setAdapter(adapter);
coverFlowTwo.setOnScrollPositionListener(onScrollListener());
myHome = (LinearLayout)findViewById(R.id.c_home);
myOrder = (LinearLayout)findViewById(R.id.c_my_order);
myAccount = (LinearLayout)findViewById(R.id.c_profile);
myHome.setOnClickListener(this);
myOrder.setOnClickListener(this);
myAccount.setOnClickListener(this);
}
private void selectFirstItemAsDefault() {
if (mNavigationManager != null) {
String firstActionMovie = getResources().getStringArray(R.array.actionFilms)[0];
mNavigationManager.showFragmentAction(firstActionMovie);
}
}
private void initItems() {
items = getResources().getStringArray(R.array.film_genre);
}
private void addDrawerItems() {
mExpandableListAdapter = new CustomExpandableListAdapter(this, mExpandableListTitle, mExpandableListData);
mExpandableListView.setAdapter(mExpandableListAdapter);
mExpandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
String selectedItem = ((List) (mExpandableListData.get(mExpandableListTitle.get(groupPosition))))
.get(childPosition).toString();
mDrawerLayout.closeDrawer(GravityCompat.START);
return false;
}
});
}
private void setupDrawer() {
mDrawerToggle = new ActionBarDrawerToggle(this,
mDrawerLayout,
R.string.drawer_open,
R.string.drawer_close) {
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu();
}
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getSupportActionBar().setTitle(mActivityTitle);
invalidateOptionsMenu();
}
};
mDrawerToggle.setHomeAsUpIndicator(R.drawable.menu_icon);
mDrawerToggle.setDrawerIndicatorEnabled(false);
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerLayout.requestLayout();
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
あなたは '(偽)mDrawerToggle.setDrawerIndicatorEnabledこの行をドロップしようとした持っている。そして、私は(真)mDrawerToggle.setDrawerIndicatorEnabled'試みた ' が、何も も、その後起こりません;' –
は、はい私は(偽)mDrawerToggle.setDrawerIndicatorEnabled '落としてみました。 ' しかし、これはデフォルトのトグルハムアイコンと' mDrawerToggle.setDrawerIndicatorEnabled(false);と を与えます。私のカスタムアイコンを見ることができますが、それはクリックを受け取りません –