Android NavigationView : not show full item and not truncate - android-support-library

Problem : NavigationView not show full text of menu item, also not truncate text.
This item I see correctly - two words "Small title":
<item
android:id="#+id/example1"
android:icon="#drawable/filter_2"
android:title="Small title"
android:checked="false"
app:actionLayout="#layout/menu_counter" />
/>
And with next item - I see only first two words "Small title" without any truncate of next word "andveryverylongword":
<item
android:id="#+id/example2"
android:icon="#drawable/filter_2"
android:title="Small title andveryverylongword"
android:checked="false"
app:actionLayout="#layout/menu_counter" />
/>
Widget :
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
ndroid:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer"/>
Also : AndroidStudio 1.5, support library.
EDITED :
Here is example of standart project "Navigation Drawer Activity" in Android Studio.
activity_main_drawer.xml :
in mobile :

I just got this working
* Override design_navigation_item.xml and change it to use
android:layout_height="wrap_content"
android:minHeight="?android:listPreferredItemHeightSmall"
Override design_navigation_menu_item.xml to use maxLines=2
Kinda cool, I can't believe that works. Thanks to the guy on stackoverflow that talked about overriding icon size, which helped me thinking in this direction.

Add app:itemMaxLines="2" in NavigationView of your layout.
That worked for me.
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
app:itemMaxLines="2"
android:background="#color/background_color"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />

Related

Do not center Placeholder in TextInputLayout vertically

I am using Material Components 1.1.0. On a TextInputLayout I removed the background and left-aligned the placeholder and text by setting the paddingStart of the EditText to zero.
This gives me the following result:
Note the large distance between the Placeholder and the bottom line.
When actually typing text, the distance between the text and the bottom line is much smaller:
I want the Placeholder to have the same distance from the bottom line as the real text. How can I do this?
Used style:
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<item name="textInputStyle">#style/textInputLayout</item>
</style>
<style name="textInputLayout" parent="Widget.MaterialComponents.TextInputLayout.FilledBox.Dense">
<item name="boxBackgroundColor">#color/transparentWhite</item>
</style>
Used TextInputLayout:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/spacing_normal"
app:layout_constraintEnd_toStartOf="#+id/guideline_end"
app:layout_constraintStart_toStartOf="#+id/guideline_start"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/text_contract_partner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Stackoverflow"
android:paddingStart="0dp"
android:paddingEnd="0dp"
/>
</com.google.android.material.textfield.TextInputLayout>
You can extend the component and write your own behaviour. #Gabriele Mariotti is a grand master in Material Design, and I think, he is right. You can ask for this feature.
This is a bit ugly solution, it has no animation due to toggling between hints.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/spacing_normal"
app:hintTextAppearance="#android:style/TextAppearance.Medium"
app:layout_constraintEnd_toStartOf="#+id/guideline_end"
app:layout_constraintStart_toStartOf="#+id/guideline_start"
app:layout_constraintTop_toTopOf="parent"
android:hint="Stackoverflow"
app:hintEnabled="false"
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/text_contract_partner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Stackoverflow"
/>
</com.google.android.material.textfield.TextInputLayout>
text_contract_partner.setOnFocusChangeListener { v, hasFocus ->
if (hasFocus) {
textInputLayout.isHintEnabled = true
} else {
if (text_contract_partner.text.toString().isEmpty()) {
textInputLayout.isHintEnabled = false
}
}
}
1) Unfocused state with empty text:
2) Focused state with empty text:
3) Focused state with text:
4) Unfocused state with text:

NativeScript Angular ListPicker that behaves like `<select>`

By default the ListPicker takes up a ton of screen space. Is there a way to make it behave like the metaphor for the HTML <select> when shown on mobile?
I've used this react native plugin before, and its exactly the metaphor I want, but for NativeScript.
Is this easy to do via NativeScript? I want to make use of the platform specific select metaphors, so showing/hiding a ListPicker or putting ListPicker in a modal is not what I'm looking for.
Also, I'm going to have a fairly long list, so an action Dialog wont work for me.
Update: I'm aware of nativescript-drop-down, however it does not use the platform specific "choose from list of choices" widget that webviews and react native plugin do.
By "platform specific choose from list of choices widget" I mean this (from https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select):
iOS (note picker renders where keyboard would, with rolodex picker):
Android (note modal, with scroll list of options):
I think you are looking for the nativescript-drop-down which is similar to the react-native-picker-select you had pointed.
I was looking for the same solution and couldn't find one so I have created my own. I have attached a sample for you here.
You can have a textField/Label and onTab you can show the ListPicker, like Select behaves in HTML and it will use the native(platform specific) components only.
in your HTML
<StackLayout orientation="vertical" width="210" height="210" backgroundColor="lightgray">
<Label text="Country" width="70" height="50" backgroundColor="red"></Label>
<TextField [(ngModel)]="textFieldValue" hint="Choose countty..." editable="false" (tap)="showHideField('country')"></TextField>
</StackLayout>
<StackLayout orientation="vertical" width="100%" height="210" *ngIf="showCountryPicker" backgroundColor="lightgray">
<ListPicker [items]="listPickerCountries" (selectedIndexChange)="selectedCountyChanged($event)"></ListPicker>
</StackLayout>
and your .ts file
showCountryPicker = false;
listPickerCountries: Array < string > = ["Australia", "Belgium", "Bulgaria", "Canada", "Switzerland",
"China", "Czech Republic", "Germany", "Spain", "Ethiopia", "Croatia", "Hungary",
"Italy", "Jamaica", "Romania", "Russia", "United States"
];
showHideField() {
this.showCountryPicker = true;
}
selectedCountyChanged(args) {
const picker = < ListPicker > args.object;
this.showCountryPicker = false;
this.textFieldValue = this.listPickerCountries[picker.selectedIndex];
}

Nativescript – center horizontal text inside textView, dynamic text and multiline

I've got a nativescript app. I have a situation were I need to display text dynamically, so I don't know how much text and how much lines it will be.
The text need to wrap over multi lines and has to be aligned in center horizontally (not vertically, simply same distance to left and right) always.
Therefore I guess <Label> isn't the right element, because it is not for multiline (if I got this right?!).
So I choose <TextView>, but here the styles text-align: center got ignored.
So in documentation I found constructor textAlignment https://docs.nativescript.org/api-reference/modules/_ui_text_base_#textalignment, but I don't get it to work.
Doesn't work:
<TextView text="{{ taskString }}"
horizontalAlignment="center"
editable="false"
></TextView>
Doesn't work:
<TextView text="{{ taskString }}"
textAlignment="center"
editable="false"
></TextView>
Please let me know, what obvious I didn't get here. Thx.
Upate:
Label with textWrap="true" normally works just fine. But I have a "complex" <ContentView> <FlexboxLayout> combination, that seems to cause the problem with the height of Label that doesn't get updated.
Solution in my case:
Just don't use a <FlexboxLayout> <FlexboxLayout> ... </FlexboxLayout> </FlexboxLayout>solution. That won't calculate the height of Label dynamically.
Nativescript Playground:
https://play.nativescript.org/?template=play-ng&id=SnNmkQ
Label can be multiline if you enable textWrap
XML
<Label text="{{ taskString }}" textWrap="true" ...
Or
CSS
Label {
white-space: normal;
}

Any way to set editActions on a ListView with dataCollection?

I have a ListView that's hooked to a dataCollection, is it possible to add editActions?
Can't seem to find a way to add these to my ItemTemplate or ListItem.
Here's my (shortened) view:
<ListView id="listViewSpots" defaultItemTemplate="history">
<Templates>
<ItemTemplate name="history" id="itemTemplateHistory" canEdit="true">
<Label bindId="serie" class="serie" />
</ItemTemplate>
</Templates>
<ListSection id="listSectionSpots" dataCollection="spot" dataFilter="listFilter">
<ListItem itemId="{id}" serie:text="{serie}" searchableText="{serie}" />
</ListSection>
</ListView>
You can add custom actions like this:
"ListItem[platform=ios]":{
accessoryType: Titanium.UI.LIST_ACCESSORY_TYPE_DISCLOSURE,
editActions: [{ title: "Add",
style: Ti.UI.iOS.ROW_ACTION_STYLE_DEFAULT },
{ title: "Archive",
style: Ti.UI.iOS.ROW_ACTION_STYLE_DEFAULT },]
}
Editable and EditActions are just regular properties of a ListItem and can be added as such. Through a transform function (dataTransform) you can make this customizable as well
<ListView id="listViewSpots" defaultItemTemplate="history">
<Templates>
<ItemTemplate name="history" id="itemTemplateHistory" canEdit="true">
<Label bindId="serie" class="serie" />
</ItemTemplate>
</Templates>
<ListSection id="listSectionSpots" dataCollection="spot" dataFilter="listFilter">
<ListItem
itemId="{id}"
serie:text="{serie}"
searchableText="{serie}"
editable="{editable}"
editActions="{editActions}"
/>
</ListSection>
</ListView>
This way you can still configure it per ListItem
Yes it is possible.
Can you specify your issue ?
Can you enable slide action?
Do you wanna know how to handle click event?
Maybe this can help you:
"ItemTemplate[platform=ios]":{
canEdit: true
}

how to set a backgroundColor from a js in appcelerator Titanium Alloy MVC

I have a small Question about setting Tab Names Dynamically.
I am Thinking to create an options.js and I want my tab names to gather data from options.js
<Alloy>
<TabGroup>
<Tab title="Tab 1" icon="KS_nav_ui.png">
<Window class="tab1" title="Tab 1">
<Label>I am Window 1</Label>
<Button class="exampleBut">Button </Button>
</Window>
</Tab>
</TabGroup>
</Alloy>
I would like to set Tab 1 Title from another JS file.
How to solve it ?
Regards
You have to identify the tab by a unique id
<Tab title="Tab 1" id='tab1' icon="KS_nav_ui.png">
in the same js file for exemple index.js (the tab is defined in index.xml) you can use :
$.tab1.title="my title"
if you would set title from another js file you can use application events:
in index file you define an application event listener :
Ti.App.addEventListener("app:changeTabTitlle",function(e){
$.tab1.title=e.title;
});
and from the other js file you have to send the tab title using fireEvent:
Ti.App.fireEvent("app:changeTabTitlle",{title:"My tab title"});

Resources