현재 개발 중이며 Api10을 지원해야하는 Android 앱 + 많은 자습서를 따라 appcompat을 설정하여 작업 표시 줄을 만들었습니다.Android appcompat API 10 축소 동작보기
링크가 좋아하는 : 내가 할 수없는 경우에만 세 가지가 있습니다 https://stackoverflow.com/a/21291156/2789106 http://developer.android.com/guide/topics/ui/actionbar.html
.
- 검색을 열면 검색 돋보기가 내가 설정 한 드로어 블로 변경되지 않습니다.
- 내가 "뒤로"아이콘을 변경할 수 없습니다
- 내가 할 수있는 프로그램 가깝지 (붕괴)을 (로고 왼쪽에서 홈까지 버튼을, (그것은 내가
drawerToggle
의 창조) 전달 된 것보다 diferrent 이미지입니다) 키보드 검색을 클릭하면 액션보기.
여기 내 코드입니다 (collapseActionView()
를 호출은 API 14 inplemented되었다) :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ActionBarDrawerToggle ties together the the proper interactions
// between the sliding drawer and the action bar app icon
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_navigation_drawer,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
// Restore app state if any
if (savedInstanceState == null) {
mLeftMenuContainer = (LinearLayout) findViewById(R.id.left_menu_container);
mLeftMenuContainer.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// return TRUE to avoid tap on back view
return true;
}
});
mDrawerLayout.closeDrawer(mLeftMenuContainer);
}
// enable ActionBar app icon to behave as action to toggle nav drawer
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setLogo(R.drawable.ic_action_bar_logo);
}
/* Called whenever we call supportInvalidateOptionsMenu() */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// If the nav drawer is open, hide action items related to the content
// view
if (mDrawerLayout != null && mLeftMenuContainer != null) {
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mLeftMenuContainer);
for (int i = 0; i < menu.size(); i++) {
menu.getItem(i).setVisible(!drawerOpen);
}
}
return super.onPrepareOptionsMenu(menu);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
mMenu = menu;
// Inflate the menu; this adds items to the action bar if it is present.
// enable ActionBar app icon to behave as action to toggle nav drawer
getMenuInflater().inflate(R.menu.main, menu);
MenuItem searchItem = menu.findItem(R.id.action_bar_search);
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
searchView.setSearchableInfo(info);
AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchText.setHintTextColor(getResources().getColor(R.color.color_action_bar_search_text));
searchText.setTextColor(getResources().getColor(R.color.color_action_bar_search_text));
searchView.setIconifiedByDefault(true);
// Getting the 'search_plate' LinearLayout.
View searchPlate = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
// Setting background of 'search_plate' to personal defined drawable.
if (searchPlate != null) {
searchPlate
.setBackgroundResource(R.drawable.texfield_search_view_theme);
}
// Set search view clear icon
ImageView searchIconClearView = (ImageView) searchView
.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
if (searchIconClearView != null) {
Log.v(LOG_TAG, "Should Change Clear Icon here");
searchIconClearView
.setImageResource(R.drawable.ic_action_bar_clear_search);
}
// Set search view Magnifier icon
ImageView searchIcon = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
if (searchIcon != null) {
Log.v(LOG_TAG, "Should Change Search Icon here");
searchIcon.setImageResource(R.drawable.ic_action_bar_back);
}
// Set on click to open a fragment, not a activity
final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
// Do something
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
Log.v(LOG_TAG, "Performed search with: " + query);
searchView.clearFocus();
return true;
}
};
searchView.setOnQueryTextListener(queryTextListener);
MenuItemCompat.setOnActionExpandListener(searchItem, new OnActionExpandListener() {
@Override
public boolean onMenuItemActionCollapse(MenuItem arg0) {
mMenu.findItem(R.id.action_bar_cart).setVisible(true);
return true;
}
@Override
public boolean onMenuItemActionExpand(MenuItem arg0) {
getSupportActionBar().setIcon(R.drawable.ic_action_bar_logo);
mMenu.findItem(R.id.action_bar_cart).setVisible(false);
return true;
}
});
return super.onCreateOptionsMenu(menu);
}
내가 뭔가 잘못하고있어 경우에 누군가가 말해 주시겠습니까?
당신이해야 할 것은 당신의 테마에 homeUpIcon을 정의하는 것입니다 :
- - 편집
나는 질문 번호 1과 2를 해결하기 위해 관리. 그래서 나 같은 API (10)를 지원하는 경우 :
<style name="Theme.MyTheme" parent="@style/Theme.AppCompat.Light">
<item name="searchViewSearchIcon">@drawable/your_search_icon</item>
<!-- API 13- Support -->
<item name="homeAsUpIndicator">@drawable/your_back_icon</item>
<!-- API 14+ -->
<item name="android:homeAsUpIndicator">@drawable/your_back_icon</item>
</style>
발견 Changing the background drawable of the searchview widget
가장 중요한 질문
ActionBarSherlock: changing homeAsUpIndicator doesn't work
및 에 아직 보류중인 사람이 답을 알고있는 경우 여기를 게시하시기 바랍니다 있습니다!
나는'응용 프로그램과의 MenuItem 설치해야했다 : showAsAction = |이 작동합니다 전에' "collapseActionView을 항상". –