2016-12-09 8 views
1

私はこれをかなりの間処理してきました。しかし成功はありません! 私がしたいのは、カスタムレイアウトをアプリケーションバーの左端に設定することです。まったく何もありません。しかし、私が何を変えても、レイアウトはそれ以上は変わりません。アライメントができないため、カスタムバーをアプリバーに残しました

enter image description here

私のstyles.xml

<resources xmlns:tools="http://schemas.android.com/tools"> 
<!-- colorPrimary is used for the default action bar background --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar" > 
    <item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">true</item> 
    <!--<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>--> 
    <item name="colorPrimary">@color/blue4main</item> 
    <item name="colorPrimaryDark">@color/blue5</item> 
    <item name="android:textColor">@color/black1</item> 
    <item name="android:textColorPrimary">@color/blue6</item> 
    <item name="android:textColorSecondary">@color/blue1</item> 
    <item name="android:textColorPrimaryInverse">@color/blue3</item> 
    <!----> 
    <item name="android:contentInsetLeft" tools:targetApi="lollipop">0dp</item> 
    <item name="android:contentInsetStart" tools:targetApi="lollipop">0dp</item> 

私custom_toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:layout_gravity="left" 
      android:background="@color/black1" 
      android:gravity="left|center_vertical" 
      android:layoutDirection="ltr" 
      android:contentInsetStart="0dp" 
      android:contentInsetLeft="0dp" 
      app:contentInsetLeft="0dp" 
      app:contentInsetStart="0dp" 
      android:orientation="horizontal"> 
    ... 

やコード:

private void insideOnCreateForVicinity() { 
    ActionBar actionBar = getSupportActionBar(); // you can use ABS or the non-bc ActionBar 
    if (actionBar != null) { 
     actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_HOME_AS_UP |ActionBar.DISPLAY_SHOW_TITLE); 
    } 

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View layout = inflater.inflate(R.layout.vicinity_and_filtercone_search_bar, null); 
    // the view that contains the search "magnifier" icon 
    final ImageView searchIcon = (ImageView) layout.findViewById(R.id.search_mag_icon); 
    final ImageView filterConeIcon = (ImageView) layout.findViewById(R.id.ic_filter_cone); 
    final DelayAutoCompleteTextView textViewVicinity = (DelayAutoCompleteTextView) layout.findViewById(R.id.text_view_vicinity); 
    textViewVicinity.setThreshold(3);//after how many letters users types, send the request. 
    textViewVicinity.setAdapter(new VicinityAutoCompleteAdapter(this)); 
    textViewVicinity.setLoadingIndicator((android.widget.ProgressBar) layout.findViewById(R.id.progress_bar)); 
    textViewVicinity.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { 
      VicinityPageItem p = (VicinityPageItem) adapterView.getItemAtPosition(position); 
      textViewVicinity.setText(p.Name); 
      textViewVicinity.setSelection(textViewVicinity.length());//put the cursor at the end 
      searchFilter.setVicinityID(p.ID);//hamed. kesafate in 
      reload(searchFilter); 
     } 
    }); 
    actionBar.setCustomView(layout); 

私は以下のリンクを試してみましたが、いくつかしましたその他、非は私のために働いた: (まだレイアウトファイルに重力を設定することはなかった、なぜ私はまだ知らない。

How to align items in action bar to the left? Add custom layout to ActionBar with Gravity Left? Android API 21 Toolbar Padding

+0

多分picutre? – creativecreatorormaybenot

答えて

0

this answerためAmrut Bidriのおかげで、私は解決策を見つけました仕事)

ActionBar.LayoutParams lp = (ActionBar.LayoutParams) layout.getLayoutParams(); 
    lp.gravity = Gravity.LEFT; 
    layout.setLayoutParams(lp); 
関連する問題